What is it?
To start off if you were/are like me, I started off thinking the Udoo was this awesome thing that I could easily access the Linux side with a library, yet I got disappointed because I had to handle the Serial comm and It got really annoying, the more I messed around with it the more i felt like the Udoo was 2 micro-controllers/processors drifting apart, So I tried looked online and didn't find anything, for a library that handled the serial line. Then I decided to make one!
Now?
I have created a library for the Udoo that allows the Use of the multi threaded Imx6 to work with the single threaded Sam3x, Imagine the Linux side communications as a Library that just gets slapped on into Arduino IDE!! That's exactly what this is All you have to do is run a python script on one side, and the Serial comm/Networking/Storage/Audio Threads are handled for you, well on the other side there are many functions to call those threads on the Linux side. Which are simple to use for anyone.
How to use it?
Download the zip on the GitHub repo. The Linux folder gets placed on your desktop, and... and.. that's pretty much it, just install pyserial if not already installed on the new OS for Udoo
The Udoo-Lib will go into the arduino libraries folder (I believe /home/ubuntu/Arduino/libraries/)
If you don't know what to do
Here: 1. Open Arduino
2. Go to file -> examples
3. Select an example that you'll need
4. Modify the Code
5. If using tcp or udp make sure you have a server/client running on separate device
6. Upload the Arduino sketch
7. wait until the Sam resets,
8. Grab a female to female jumper cable and use it as a switch to reset the Sam3x manually that is located next to the J16 slot, place one end into the male then to reset quickly insert into the other J16 port (male), then unplug one side to reset the Sam
9. Run the Python Udoo.py sketch
10. If: it found the Sam and there weren't any errors, then your good to go
11. else: Reset (Sam3x) using jumper cables
12. still: contact me
Help?
Since I just wrote this library in a couple of days, I need your guys help to fix it up and make it more efficient contact me through Gmail: smerkousdavid@gmail.com (best)
Commands?
Look farther down for examples
Here are the base for the below commands <Return> <name(<Input>)>
Udoo Class:
void init(void); //MUST be called, this tells the Linux side script to start, practically put this anywhere you want, but must be before any other Udoo commands
void stop(void); //Stops Serial line so you can use it, but remember to call Serial.begin() after stop if you want to use the Serial line
void debug(String text); //Here is a substitute for debugging, since Serial line is used, you must use this command to print to Script console
String getIp(void); //Returns the current Ip of the udoo
void linuxCommand(String command); //Runs a terminal command on linux
TcpClient Class:
void connect(String ip, int port); //Tell the script to connect to a TCP server using the ip and port plugged in, only need to call this once
void send(String text); //Sends a whole line to the server
String recv(void); //Receive a full line from the server
void close(void); //Closes the Tcp connection
TcpServer Class:
void start(int port); //Starts a Tcp Server on port
void stop(void); //Stops the Tcp Server
void clientWait(int delay); //Call this before a connection with client and insert delay time afterwards, I would put 10 milliseconds what worked best for me
void send(String message); //Send a full line to the Client
String recv(void); //Receive a full line from the Client
void close(void); // Close the client connection
UdpClient Class:
void connect(String ip, int port); //Tell the script to connect to a UDP server using the ip and port plugged in, only need to call this once
void send(String text); //Sends a whole line to the server
String recv(void); //Receive a full line from the server
UdpServer Class:
void start(int port); //Starts a Udp Server on port
void stop(void); //Stops the Udp Server
void send(String message); //Send a full line to the Client
String recv(void); //Receive a full line from the Client
Storage Class:
String readFile(String directory); //Reads any file turns it into a string and includes newlines
void writeFile(String directory, String toWrite); //Creates/Overwrites a file on the Linux side with some initial text/image stuff
void appendTo(String directory, String toWrite); //Without overwriting, this function will add to the file
String readLine(String directory, int lineNum); //Retrieve a specific line from the file starts at 0
Usb Class:
void start(String port, int bitrate); //Starts a serial line with a Usb device on the Linux side
void write(String toWrite); //Writes a full line to the Serial line
String read(String directory, String toWrite); //Reads and returns a full line from the Serial line
void stop(void); //Stops that Serial line
Examples?
Custom Linux Command
#include <Udoo.h> Udoo udoo; void setup() { udoo.init(); //Allways needed before any other Udoo command udoo.linuxCommand("echo This command came from the Arduino side"); udoo.stop(); //Stop Serial line if you want to use it for something else } void loop() { //Nothing }
Debug
#include <Udoo.h> Udoo udoo; void setup() { udoo.init(); //Must be called before other commands udoo.debug("LINE 1"); //The debug command auto creates new line udoo.debug("Hello World!\nLine three");//You can also manually insert new line udoo.stop(); //Stop serial line } void loop() { //Do nothing... }
Storage
#include <Udoo.h> Udoo udoo; Storage storage; String file = "/home/ubuntu/Desktop/TEST.txt"; void setup() { udoo.init(); //Start serial line /* Writing to A file */ storage.writeFile(file,"Line 1\nLine 2");//This will overwrite/create new file storage.appendTo(file, "Line 3"); storage.appendTo(file, "Line 4\nLine 5"); //Append without rewriting to a file //These autoclose so there isn't a close function /* Reading from a file */ Strign fileText = storage.readFile(file); //Will return string from file udoo.debug("In the file: "+fileText); String oneLine = storage.readLine(file, 0); //Pull first line from file String lineTwo = storage.readLine(file, 1); //Pull second line from file udoo.debug("First line: "+oneLine+"\nSecond Line: "+lineTwo); } void loop() { //Nothing }
TcpClient
#include <Udoo.h> Udoo udoo; TcpClient client; void setup() { udoo.init(); //Must call this before any other udoo commands client.connect("192.168.1.250", 8080); //Set Ip and port for TcpClient } void loop() { client.send("From Udoo"); //Send String to Server udoo.debug(client.recv()); //Recieve from server then send to console client.close(); //Close the socket delay(1000); }
TcpServer
#include <Udoo.h> Udoo udoo; TcpServer server; void setup() { udoo.init(); //Must be called before any udoo commands server.start(8080); //Start tcp server //To stop a server use server.stop() String ip = udoo.getIp(); //Get the current Linux side Ip address debug(ip); //Debug on the console the current ip (Function below) } void loop() { server.clientWait(10);//Wait until a client connect,then delay 10 milliseconds debug("Got Client"); debug(server.recv()); //Recieve from server and print to console server.send("Got it bud!"); //Send back to Client server.close(); //Close the client connection } void debug(String toDebug) { udoo.debug(toDebug); //Just a function to make the call smaller }
UdpClient
#include <Udoo.h> Udoo udoo; UdpClient client; void setup() { udoo.init(); //Must call this before any other udoo commands client.connect("192.168.1.250", 8080); //Set Ip and port for udpClient } void loop() { client.send("From Udoo");//Send String to Server(Udp client should send first) udoo.debug(client.recv()); //Recieve from Server and print result to console delay(1000); }
UdpServer
#include <Udoo.h> Udoo udoo; UdpServer server; void setup() { udoo.init(); //Start serial line with Linux server.start(8080); //Start Udp Server on port 8080 } void loop() { String response = server.recv(); //Must recieve first before sending for udp debug("Got from client: "+response); //Send to debuging server.send("From the Udoo"); //Send message back to client } void debug(String message) { udoo.debug(message); }
Usb
#include <Udoo.h> Udoo udoo; Usb usb; void setup() { udoo.init(); //Must call this before any other udoo commands usb.start("/dev/tty", 115200); //("Port", bitrate) usb.send("Hello from udoo Serial to Serial"); //Please don't use newline udoo.debug("Got from usb: "+ usb.read()); //wait until readline on usb port usb.stop(); //Close the line } void loop() { }
Soon to come Audio
Comments