Add an Arduino device
In this case tutorial, we would show you how to add an Arduino device step by step. Here are the main steps of the tutorial:
Step 2. Fill in the detail information of the device
Step 3. Add a block category to the device
Step 4. Transcode to Arduino C
Step 5. Configure connection with the device
Step 6. Upload transcode configuration
Step 7. Preview and self-test by connecting with the device
Step 1. Add a new device
Once you’ve logged in to the extension builder, find “My Device” dashboard in “My Plugin”. Click the “Add device” button and fill in the details.
Step 2. Fill in the detail information of the device
Enter the “ID”, “Version”, “Name”, and “Support platform” where you are going to use the device. Click “OK” to save the information.
Note: Please set the support platform for your device based on its characteristics and perform a self-testing before you submit for publishing.
Step 3. Add a block category to the device
1. Click the name to enter the editing dashboard.
2. Click “Add category” in “Blocks settings” section.
3. Enter the category name and click “OK” to start the configuration.
4. Click “+” to add a block to the block list. Then define the content for the block. Enter “@” to configure a parameter.
5. Set the value for the dropdown (Voltage in high and Voltage in low). To enter the second value for the dropdown, click “+” and enter “,” to separate value of the first cell and the second cell like below:
6. Set the support platform for the block and click “Save” to save the changes.
Step 4. Transcode to Arduino C
Select “Transcode settings” to transcode to Arduino C.
Here is the template code for delay and loop configuration:
// generated by mBlock5 for <your product>
// codes make you happy
//( include //)
//( lib //)
//({
this.$ALL_VARIABLES.length==0?'':this.$ALL_VARIABLES.map(v=>"float "+v+" = 0;").join('\\n')
}//)
//( declare //)
void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}
//(
void setup() {
//( setup //)
//( code //)
}
//)
void _loop() {
//( _loop //)
}
void loop() {
//( loop //)
_loop();
}
Step 5. Configure connection with the device
1. Select “Connect settings” and start configuration. Set the device (Arduino Uno in this case) serial port vendor id: 0x2A03
2. Complete “Middleware settings”, set “arduino” as the device name.
3. Complete “Upload driver settings”, select “stk500v1” as the name. Click “Save” to save the changes.
Step 6. Upload transcode configuration
1. Back to “Blocks settings” and select “Upload transcode”.
2. Go to “Events” in “Default category”. Add an event block to the blocks list.
3. Define the block content as “When Arduino Uno starts”. Set the block category as “Event”.
4. Set the support platform for the block, and also set default transcoding for scripts in combination with this block. Click “Save” to save the changes.
5. Set transcoding in “Upload transcode” and click “Save” to save the changes.
Include: <Arduino.h>,<Wire.h>,<SofwareSerial.h>
Code:/*{$BRANCH}*
6. Translate all the blocks. Go to “Translate settings” dashboard, copy the value in “简体中文” and paste it into “English” textbox.
Step 7. Preview and self-test by connecting with the device
1. Click “Preview” button to publish and preview the plugin.
2. Connect with the device.
3. Program the device with the customized blocks like below. After uploading the code to the device, the yellow light on Arduino Uno would flash for 10 times. And you’ve successfully added an Arduino device with mBlock Extension Builder!