Hi
When a device is programmed in ‘Upload’ mode using Arduino C code, it is possible to get ‘Upload Mode Messages’ to transfer data back to the mBlock 5 stage. To do this you need to declare suitably named variables to be used on the ‘Devices’ Tab and a similar set of variables declared to be used with any sprite on the ‘Sprites’ Tab. It makes sense if these sets of variables are similarly named (almost matching names, but not quite matching).
As a general principle, to get sensor feedback from an ‘Offline’ board to the mBlock 5 ‘Stage’ it needs a variable thgat can be used at each end of the of transmit and receive cycle. A sprite (any sprite) needs a blocks script creating to receive a NAMED broadcast message containing the value of a ‘Devices’ Tab variable and then set the value contained in that message into the matching ‘Sprites’ Tab variable so that it can be used as graphical output on the ‘Stage’.
A ‘forever’ loop (in the Arduino Code) reads a sensor and updates a declared variable called xxxSensor with that value . It then sends an ‘upload mode message’ called xxxData with the value stored in xxxSensor attached to the message.
On any Stage sprite (any sprite) a hat block ‘when receiving upload mode message (xxxData)’ is added to the sprite and immediately under the hat block, is added any actions that need to be carried out. In this case, a similarly named variable xxxxxx is set to equal the value of the data (xxxSensor) sent from the Arduino code polling the sensor.
This SENT VALUE can be displayed on the stage where the ‘when receiving upload mode message’ sprite routine will be constantly updated by the feedback from the Ultrasonic Sensor with the transmitted values. Such receiving scripts will ‘pulse’ gently as long as the Arduino code continues to send values (as it has been instructed to do) unless stopped.
Devices (Broadcasting) Script Example:
Sprite (Receiving) Script Example:
Hope this helps.
My book ‘mBot&Me - vol I’ explains and demonstrates how you can turn sensor data on the 'Stage into high-quality graphics that will update as required in real-time: You can find this at: