BBC MicroBit radio send/receive - data packet is not a string?
Posted: Mon Oct 10, 2016 11:41 pm
Evening all,
I am trying to get a seemingly simple remote control car project to work with 2 Microbits but keep getting the same error message. The controller code measures which way the controller is being tilted and sends out a f,b,l or r message to the motor board. The controller code seems to work fine.
The driver microbit always returns an error for the radio.receive() line - data packet received is not a string. This happens as soon as I tilt the controller. I have played around with the code and looked at similar examples online but cannot see where the problem is.
I use Mu which I downloaded a few weeks ago and it has worked fine. I just don't know where I am going wrong here and would like to have it ready to show the kids at this week's code club.
I have commented out the motor board outputs and am asking the driver microbit to just display images until i work this out.
Thanks in advance for any help. Let me know if you need any more info.
____Controller code____
from microbit import *
import radio
radio.on()
while True:
readingy = accelerometer.get_y()
readingx = accelerometer.get_x()
if readingy > 550:
display.show(Image.ARROW_S)
radio.send('b')
elif readingy < -550:
display.show(Image.ARROW_N)
radio.send('f')
elif readingx < -550:
display.show(Image.ARROW_W)
radio.send('l')
elif readingx > 550:
display.show(Image.ARROW_E)
radio.send('r')
else:
display.show("-")
____Driver code____
from microbit import *
import radio
radio.on()
while True:
msgin = radio.receive() ## error always reported on this line
if msgin == 'f':
#pin12.write_digital(1)
#pin16.write_digital(1)
display.show(Image.ARROW_N)
elif msgin == 'b':
#pin8.write_digital(1)
#pin0.write_digital(1)
display.show(Image.ARROW_S)
elif msgin == 'l':
#pin12.write_digital(1)
#pin0.write_digital(1)
display.show(Image.ARROW_W)
elif msgin == 'r':
#pin8.write_digital(1)
#pin16.write_digital(1)
display.show(Image.ARROW_E)
else:
#pin12.write_digital(0)
#pin16.write_digital(0)
#pin8.write_digital(0)
#pin0.write_digital(0)
display.show("-")
I am trying to get a seemingly simple remote control car project to work with 2 Microbits but keep getting the same error message. The controller code measures which way the controller is being tilted and sends out a f,b,l or r message to the motor board. The controller code seems to work fine.
The driver microbit always returns an error for the radio.receive() line - data packet received is not a string. This happens as soon as I tilt the controller. I have played around with the code and looked at similar examples online but cannot see where the problem is.
I use Mu which I downloaded a few weeks ago and it has worked fine. I just don't know where I am going wrong here and would like to have it ready to show the kids at this week's code club.
I have commented out the motor board outputs and am asking the driver microbit to just display images until i work this out.
Thanks in advance for any help. Let me know if you need any more info.
____Controller code____
from microbit import *
import radio
radio.on()
while True:
readingy = accelerometer.get_y()
readingx = accelerometer.get_x()
if readingy > 550:
display.show(Image.ARROW_S)
radio.send('b')
elif readingy < -550:
display.show(Image.ARROW_N)
radio.send('f')
elif readingx < -550:
display.show(Image.ARROW_W)
radio.send('l')
elif readingx > 550:
display.show(Image.ARROW_E)
radio.send('r')
else:
display.show("-")
____Driver code____
from microbit import *
import radio
radio.on()
while True:
msgin = radio.receive() ## error always reported on this line
if msgin == 'f':
#pin12.write_digital(1)
#pin16.write_digital(1)
display.show(Image.ARROW_N)
elif msgin == 'b':
#pin8.write_digital(1)
#pin0.write_digital(1)
display.show(Image.ARROW_S)
elif msgin == 'l':
#pin12.write_digital(1)
#pin0.write_digital(1)
display.show(Image.ARROW_W)
elif msgin == 'r':
#pin8.write_digital(1)
#pin16.write_digital(1)
display.show(Image.ARROW_E)
else:
#pin12.write_digital(0)
#pin16.write_digital(0)
#pin8.write_digital(0)
#pin0.write_digital(0)
display.show("-")