Sounds like a relatively easy project. There isn’t much more going on than combining a couple Arduino examples into one project. As you’ve no doubt found, it’s easy to find Arduino example code to interact with just about any piece of hardware, but combining them into one program can be difficult especially if you don’t have much programming experience. In Embrio, you can implement a node out of each code example and keep them isolated and encapsulated then just drag the output of your accelerometer node to the input of your graphing node.
These both seem like good nodes to add to the library so I’ll help you out with writing the nodes. I don’t have the accelerometer shield so you’ll have to do the testing. I did order one of those TFT displays to play around with, so I’ll be able to test that myself in the next few days.
To get started on learning how to make a node in Embrio, and specifically how to convert an Arduino code example into a node, you should go through the
Writing Custom Nodes section of the docs.
I made a node for the NAxisMotion which just reads 2 values and sets them as outputs. The outputs are currently float values. If this node works, you’ll probably want to replace the float outputs with Activation outputs and use the transform() function to convert from the range that the sensor reads to the range of 0 to 1. Let me know if you need help with that.
The first thing I did was get the library documents from
here, then I included the NineAxesMotion files and the utility folder to my project.
Important note: I got a compile error that the file “utility/BNO055.h” was not found. To fix this, I copied the BNO055 files from the utility folder into the base folder, then I opened NineAxisMotion.h and replaced the < and > characters on the line #include <utility/BNO055.h> with quotes and removed “utility/”. I need to investigate to see if this can be automated when importing a file.
Next I copied and pasted code into a new node with “touches physical pin” selected. In the declaration section I added the “include” lines, and declared an instance of the NineAxesMotion object. Notice that I left out the rest of the lines from the declaration section of the example code as those variables deal with timing which Embrio handles.
For the Startup block I copied all of the code except for the Serial commands and the delays. Embrio nodes should almost never use Serial commands or delay. In an Arduino program, you use Serial.print to send back data to view in the serial monitor, in an Embrio node you would send that data to node outputs.
The Every Update command does the sensor reading and assigns the value to the two outputs. Note you can use any of the sensor read functions here, I just used two of them. Also like I said above the float outputs should probably be replaced with activation outputs.
Attached is a text file with my copy of the node (it’s too big to paste into a reply because it contains the includes). Just open the text file and copy and paste the xml into an Embrio agent. It will also add the includes to your project. Try opening a connection to your Arduino and let me know if you get data on the outputs. I was able to upload this node to my Arduino but because I don’t have the hardware I can’t test it. I’ll reply again soon with a node for the TFT output, though I might need to get my hands on one before I can do anything useful with it.
File Attachment(s):
NAxisMotion_Node.txt
(2,658kb) downloaded 0 time(s).You cannot view/download attachments. Try to login or register.