{"id":51,"date":"2016-09-04T12:19:01","date_gmt":"2016-09-04T12:19:01","guid":{"rendered":"http:\/\/r.jander.me.uk\/?p=51"},"modified":"2016-09-04T12:29:26","modified_gmt":"2016-09-04T12:29:26","slug":"ev3-mailbox-messaging","status":"publish","type":"post","link":"https:\/\/r.jander.me.uk\/index.php\/2016\/09\/04\/ev3-mailbox-messaging\/","title":{"rendered":"EV3 Mailbox Messaging"},"content":{"rendered":"<p>So, I&#8217;ve carried on with my work on writing an AI2 app to send Mailbox messages via bluetooth to an EV3. I now have a platform I can work with for my particular needs.<\/p>\n<p>Before I discuss my results, I figure it&#8217;s worth covering the path that&#8217;s lead me to this point. Back in July I was showing off my <a href=\"http:\/\/www.jander.me.uk\/LEGO\/plott3r.html\">Plott3r<\/a>\u00a0at the Manchester <a href=\"http:\/\/www.bricktastic.org\/\">Bricktastic<\/a>\u00a0event. One thing the children often asked was could it write their name. The answer to this was &#8216;no&#8217; since there was no way of getting user-defined text in to the Plott3r (irrespective of no &#8216;font&#8217; being defined). So since then I have been looking at how to do this. My options have been:<\/p>\n<ul>\n<li>LEGO keyboard &#8211; very complex, but I&#8217;m still considering mechanisms.<\/li>\n<li>&#8220;Pantograph&#8221; style pen mechanism &#8211; too much backlash in my prototypes to be accurate.<\/li>\n<li>Ultrasonic triangulating system &#8211; this would work out where a stylus was over a keyboard layout. This proved too jittery and inaccurate.<\/li>\n<li>Using an old mobile phone to send a text message to the EV3.<\/li>\n<\/ul>\n<p>The last one of sending a text message seemed to be the simplest. Many kinds are used to using a touchscreen keyboard, so would be easiest to use. So the next challenge was to work out how write an App to send text to the EV3. After some searching and chatting I came across MIT&#8217;s <a href=\"http:\/\/appinventor.mit.edu\/explore\/\">App Inventor 2<\/a>\u00a0which looked perfect for the job, especially as it has EV3 support for some things. So that&#8217;s what I&#8217;ve been working on.<\/p>\n<p>Unfortunately for me AI2 doesn&#8217;t (yet) have support for Mailbox messages with the EV3. Since it has a SendBytes method for the bluetooth client I could look at how to send a &#8216;raw&#8217; Mailbox message. Thankfully there are quite a few good resources out there; two of which I found useful are:<\/p>\n<ul>\n<li><a href=\"http:\/\/ev3.fantastic.computer\/doxygen\/systemcommands.html\">http:\/\/ev3.fantastic.computer\/doxygen\/systemcommands.html<\/a><\/li>\n<li><a href=\"http:\/\/ev3directcommands.blogspot.co.uk\/2016\/01\/no-title-specified-page-table-border_94.html\">http:\/\/ev3directcommands.blogspot.co.uk\/2016\/01\/no-title-specified-page-table-border_94.html<\/a><\/li>\n<\/ul>\n<p>They had enough information in there for me to construct a simple message that I blogged about previously (<a href=\"http:\/\/r.jander.me.uk\/index.php\/2016\/08\/16\/my-first-bt-message\/\">My First BT Message<\/a>). Since then I have expanded on that to produce a procedure that can take variable input text messages.<\/p>\n<p>I&#8217;ve had to go down the path of implementing <a href=\"https:\/\/en.wikipedia.org\/wiki\/IEEE_floating_point\">IEEE 754<\/a>\u00a0so that I can send floating point numbers to the EV3. These are the reasons why:<\/p>\n<ol>\n<li>I want to send a string of text to the EV3 to be plotted.<\/li>\n<li>That text has to be sent as a Mailbox message.<\/li>\n<li>EV3g, the default language, has poor text manipulation capabilities so I&#8217;d have to send one Mailbox message per-letter.<\/li>\n<li>I implemented the text Mailbox method that can take any length message even though I&#8217;d only send one letter at a time &#8211; getting the Android device to do the text string manipulation.<\/li>\n<li>My original concept of taking each letter and looking up, using a huge switch statement, the stroke paths needed for that letter won&#8217;t work. It&#8217;s not (apparently) \u00a0possible to have a switch statement case that can match a double quote &#8220;, or a newline \\n. Oh dear.<\/li>\n<li>Since the app is already converting the text into <a href=\"https:\/\/en.wikipedia.org\/wiki\/ASCII\">ASCII<\/a>\u00a0values I could just send them over instead. That way I can match numerically on ASCII 10 and 34. This has the added advantage that I can then use array lookups instead &#8211; look up in one array for the offsets in to the stroke data.<\/li>\n<li>I can&#8217;t just send raw byte values. The EV3 uses IEEE 754 floating point for numbers, so I have to send that in a Mailbox message.<\/li>\n<li>Oh dear &#8211; AI2 doesn&#8217;t have a native IEEE 754 implementation. Oh well, let&#8217;s write my own!<\/li>\n<\/ol>\n<p>So here I am. I&#8217;ve now written an IEEE 754 implementation. It&#8217;s incomplete as it doesn&#8217;t handle underflow at all, but does do the number range that I need, zero, and NaN. I only need to send 0-255 over, but it does do most of the numbers that the EV3 will realistically need to deal with.<\/p>\n<p><a href=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/blocks-5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-52 alignleft\" src=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/blocks-5-150x300.png\" alt=\"blocks (5)\" width=\"150\" height=\"300\" srcset=\"https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/blocks-5-150x300.png 150w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/blocks-5-768x1537.png 768w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/blocks-5-512x1024.png 512w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/blocks-5-1200x2401.png 1200w\" sizes=\"auto, (max-width: 150px) 85vw, 150px\" \/><\/a><a href=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screenshot_20160904-131036.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-55 alignright\" src=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screenshot_20160904-131036-169x300.png\" alt=\"Screenshot_20160904-131036\" width=\"169\" height=\"300\" srcset=\"https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screenshot_20160904-131036-169x300.png 169w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screenshot_20160904-131036-576x1024.png 576w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screenshot_20160904-131036.png 720w\" sizes=\"auto, (max-width: 169px) 85vw, 169px\" \/><\/a><a href=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-04-at-12.59.45.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-53\" src=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-04-at-12.59.45-300x138.png\" alt=\"Screen Shot 2016-09-04 at 12.59.45\" width=\"300\" height=\"138\" srcset=\"https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-04-at-12.59.45-300x138.png 300w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-04-at-12.59.45-768x354.png 768w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-04-at-12.59.45-1024x473.png 1024w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-04-at-12.59.45-1200x554.png 1200w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-04-at-12.59.45.png 1233w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><a href=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/IMG_20160904_131100687.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-54\" src=\"http:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/IMG_20160904_131100687-169x300.jpg\" alt=\"IMG_20160904_131100687\" width=\"169\" height=\"300\" srcset=\"https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/IMG_20160904_131100687-169x300.jpg 169w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/IMG_20160904_131100687-768x1365.jpg 768w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/IMG_20160904_131100687-576x1024.jpg 576w, https:\/\/r.jander.me.uk\/wp-content\/uploads\/2016\/09\/IMG_20160904_131100687-1200x2133.jpg 1200w\" sizes=\"auto, (max-width: 169px) 85vw, 169px\" \/><\/a><\/p>\n<p>The value entered was 314159.26 but was sent\/received as 314159.25. This is correct for a 32 bit float, and is confirmed via Perl scripts and an <a href=\"http:\/\/www.h-schmidt.net\/FloatConverter\/IEEE754.html\">online converter.<\/a><\/p>\n<p>The AI2 code is available from:<\/p>\n<ul>\n<li><a href=\"http:\/\/jander.me.uk\/LEGO\/resources\/Testing_Ideas.aia\">http:\/\/jander.me.uk\/LEGO\/resources\/Testing_Ideas.aia<\/a><\/li>\n<\/ul>\n<p>and as usual is published under the\u00a0<span class=\"s1\"><a href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\">Creative Commons Attribution-ShareAlike 4.0 International License<\/a>.<\/span><\/p>\n<p>I still have a lot of work to do:<\/p>\n<ol>\n<li>I need to split the text into individual letters to send the ASCII value.<\/li>\n<li>I need to program the Plott3r to accept a stream of values and special codes to plot.<\/li>\n<li>I need to work out some form of &#8216;font&#8217; to be plotted.<\/li>\n<li>The final app needs to be written to make it easy to use.<\/li>\n<li>A LEGO\u00ae &#8216;holster&#8217; needs to be made to hold the phone \ud83d\ude42<\/li>\n<\/ol>\n<p>They&#8217;ll take a while, but I&#8217;m a good way there, I already have ideas for how to do points 1-3, especially 2-3, so we&#8217;ll see how they pan out. Updates to come.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, I&#8217;ve carried on with my work on writing an AI2 app to send Mailbox messages via bluetooth to an EV3. I now have a platform I can work with for my particular needs. Before I discuss my results, I figure it&#8217;s worth covering the path that&#8217;s lead me to this point. Back in July &hellip; <a href=\"https:\/\/r.jander.me.uk\/index.php\/2016\/09\/04\/ev3-mailbox-messaging\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;EV3 Mailbox Messaging&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[10],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-lego","category-mindstorms","tag-ieee754"],"_links":{"self":[{"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":4,"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":59,"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions\/59"}],"wp:attachment":[{"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/r.jander.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}