The issue is that your callback returns the pwm signal as a Float64 but then you try to to put it into a UInt8Msg. Julia tries to convert it and fails when it discovers the number isn't exactly an integer from 0-255. An explicit conversion such as return round(UInt8, pwm) at the end of calc_pwm should fix it.