I managed to focus some more time on tidying up my AI2 app for sending Mailbox messages via Bluetooth from my Android phone to an EV3. The EV3 code is really simple and looks like this:
The AI2 code provides two BT related buttons, Connect & Disconnect, a text box and a Go button to send the text:
When the text is entered and Go pressed it is sent as a Mailbox message with the name “beep” to the EV3, and displayed on its screen. The code to send it has to construct a message in the form:
MLenL, MLenH, 0x01, 0x00, 0x81, 0x9E, NLen, NameBytes, 0x00, TLenL, TLenH, TextBytes, 0x00
Which breakdown as:
- MLenL, MLenH = 16 bit little endian length of the rest of the message
- 0x0001 = Message counter
- 0x81 = System command, no reply
- 0x9E = Mailbox message
- NLen = 8 bit name length, including 0x00 termination
- NameBytes + 0x00 = The Mailbox name
- TLenL, TLenH = 16 bit little endian length of the text
- TextBytes + 0x00 = The Mailbox text
This in terms of code looks like:
If you would like to play with the code it’s available from my resources site at:
The code is released under the Creative Commons Attribution-ShareAlike 4.0 International License
The code above may not look much, but I’m very pleased with it 🙂 I’ve been working with MIT’s App Inventor 2 in an effort to build an app that can send text (in some form) to the EV3 for further processing – that code has managed it!
I’d extended the EV3 tilt-to-drive tutorial from the AI2 site to add in an extra button, that when pressed runs that code. It’s fixed at the moment but it encapsulates (little endian) 0x0018, 0x0001, 0x81, 0x9e, 0x5, beep\0, 0x0006, Beep!\0. All this info has been derived from the LEGO® Communications Developer Kit docs.
To test this I had a simple program, as below, running on the brick:
Press the button on the app, and the EV3 beeps – superb!
It also shows an interesting behaviour which I may well exploit in an upcoming model – I had one program running on the EV3, solely to beep, but was still able to drive the bot from my phone. Being able to externally control an EV3 whilst it is running its own program has a lot of merit.
At the Bricktastic event back in July I showed off my Plott3r as part of the Mindstorms exhibits. It was programmed to do the Hilbert and Dragon curves, several plot “files” and some other bits.
One of the questions that the kids kept asking was something along the lines of “can it write my name?” Unfortunately it wasn’t, and isn’t, capable of writing ad-hoc text. So since then I’ve been pondering ways of supplying user-provided text. I did consider an ultrasonic triangulated “keyboard”, but the US sensors got confused with each other’s signals – so for the moment I’ve put that idea to bed to be revisited in the future. My original thought, however, was “can I do this with a mobile phone?”
Since that original thought I’ve been looking at how to write an Android app that has a simple text box and “send” button. Kids are used to mobiles these days, so it seems to me to be the perfect UI. So far I seem to have settled on using MIT’s App Inventor 2. It does support EV3 to some extent, but I’m going to have to get down and dirty with the EV3 byte code to send mailbox messages via bluetooth 🙂
So, now I need to get learning how this AI2 system works. Thankfully they have tutorials, so I’ll be building the tilt/move tutorial soon to get to grips with communicating with the EV3. Tinkering with bytecode won’t be too daunting as I’m used to getting down to that level of bit twiddling via my current and previous jobs.
Nothing to show yet, but watch this space!
I have now completed the BIs and commented the code to the RobotRemix3 DuckToppl3r! The announcement of the MCP RR3 challenge can be found at: http://www.thenxtstep.com/2016/07/robot-remix-3.html
My guest blogger post can also be found at: http://www.thenxtstep.com/2016/07/duck-toppl3r-robotremix3.html
The BIs and code are available from:
Enjoy – I did doing this 🙂
LPub4 offers a way to add text to a page, but no option for text to appear on every page. Whilst working on the BIs for the DuckToppl3r I had a need to put a disclaimer on each page. I am lead to believe that LPub3D can do this, but that is currently a Windows-only program. Since LDraw and LPub4 use text and I’m no stranger to Perl I figured a quick script would come to my rescue 🙂
LPub4 produces a new page on each STEP or ROTSTEP statement when not in a multi-step page, or on a “MULTI_STEP END” statement. So, all I needed to was to output the same “INSERT TEXT” statement above one of those three where relevant. The code used is as below if this proves to be useful to anyone:
$first = 'The MINDSTORMS® Community Partners present ROBOTREMIX3 [31313 + 42050] Community Challenge 2016. DUCK TOPPL3R Design & Building Instructions by Jerry Nicholls.';
$second = 'MINDSTORMS is a registered trademark of The LEGO Group. This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. August 2016';
GetOptions( 'first=s' => \$first, 'second=s' => \$second );
$multi = 0;
$multi = 1 if /MULTI_STEP\s+BEGIN/;
if ((!$multi && /^0\s+(?:ROT)?STEP\s/) ||
$multi = 0;
0 !LPUB INSERT TEXT "$first" "Helvetica,18,-1,5,75,0,0,0,0,0" "Black" OFFSET 0.06 0.935
0 !LPUB INSERT TEXT "$second" "Helvetica,18,-1,5,75,0,0,0,0,0" "Black" OFFSET 0.06 0.95
I’m going to try to start to blog about the models I’ve built, those I’m pondering on, and those that are in progress.
Some weeks back I started on the RobotRemix3 DuckToppl3r project (http://www.thenxtstep.com/2016/07/robot-remix-3.html) and am very close to releasing the BIs (Build Instructions) and the .EV3 code file to the public. When that happens, I’ll blog on here again. In the meantime here’s a link to TNS’s article on it: http://www.thenxtstep.com/2016/07/duck-toppl3r-robotremix3.html
For simplicity I’ll probably keep my BIs and code on my original site to save lots of copying around.