9 Replies Latest reply on Apr 14, 2015 8:10 AM by KurtE

    Intel Edison and Arduino Uno

    PeterOdd

      Hi,

       

      I'm using an Arduino Uno (not Arduino expansion board) to get sensor data (from a Muscle Sensor v3) and that is working as expected. I send the data using Serial.begin(9600)... Serial.println(value_to_send), I can read the output correct on my laptop using serial monitor.

      Issue: I want to get the output from the Arduino Uno to my Intel Edison and read it using python or C code so I can process it there and later send it using Bluetooth to a smartphone or a computer. How can I achieve this connection between the Arduino and the Edison?

       

      Hardware:

      * Intel Edison with Mini Breakout Board

      * Arduino Uno

      * Muscle Sensor v3

       

      This is the flow I'm looking for:

      * Arduino reads data and sends it to Intel Edison.

      * Intel Edison reads that data using Python or C code.

      * Intel Edison sends data to smartphone or computer using Bluetooth (later issue, but thought you should know what I'm aiming at).

       

      Thank you!

        • 1. Re: Intel Edison and Arduino Uno
          Frederick Blais

          Here is an example serial read with Python

           

          import serial
          import mraa
          
          #Init
          uart = mraa.Uart(0)
          ser = serial.Serial(uart.getDevicePath(), 9600)
          
          ser.write("TEST")
          print ser.read(4)
          
          

           

          I just shorted the RX and TX pin on my Arduino Breakout.

          You need to have pip and install the "pyserial" module.

           

          On your mini breakout you will need to level shift your TX and RX for the 5V to 1.8V.

           

          Don't hesitate to ask if you have any questions. For Bluetooth, I can help you when you get there, but first get the serial stuff to work

          It would also be interesting to know if you have Android phone or iPhone, if you plan to make an app or just display to a serial Bluetooth terminal on your phone.

           

          You could also take a look at the Intel XDK : Intel® XDK IoT Edition | Intel® Developer Zone

          • 2. Re: Intel Edison and Arduino Uno
            PeterOdd

            Thank you! I will definitely ask you later when I'm heading for bluetooth! Right now I'm thinking of an app to display various data on a phone (iPhone or android). I was first planning to do Swift for iPhone but thought yesterday of HTML, CSS and JavaScript together with Framework 7 (don't know if doable yet re. bluetooth) or similar to make the app platform independent.

             

            Do the mini breakout really have TX and RX? (I have this board: Intel® Edison and Mini Breakout Kit - DEV-13025 - SparkFun Electronics)
            How would I connect the Arduino to the Edison?

             

            Thank you!

            • 3. Re: Intel Edison and Arduino Uno
              Frederick Blais

              Yes the Mini Breakout have an UART peripheral. Take a look here for pinout : mraa: Intel Edison

              Looks like J18-13 is RX and J19-8 is TX.

               

              For level translation you could use something like this : SparkFun Voltage-Level Translator Breakout - TXB0104 - BOB-11771 - SparkFun Electronics

              Or do it yourself like in the picture below. Take care, Raspberry Pi is 3.3V (not 1.8V) device so set the resistors value accordingly.

              RPi-Shifter1.png

               

              In my opinion, deciding to go Bluetooth is deciding to go the hard way. The iPhone is not really maker friendly for the Bluetooth. I managed to do it on Android but I had to learn to make Android apps with Android Studio.

               

              Depending on what you want to achieve, I would personally host a little web page on the Edison that would give you the data you need. That way, you can access the data with any device that have a web browser (PC, iPhone, Android...)

               

              My favorite choice for web framework is Flask for Python : Welcome | Flask (A Python Microframework)

               

              And if I had to read the sensor, I would probably ditch the Arduino and use an ADC like the MCP3204 to do it all on the Edison.

               

              Fred

              • 4. Re: Intel Edison and Arduino Uno
                PeterOdd

                Thanks!

                I was wondering if there is no way to read the input on J16 on the Edison? The Arduino sends data on serial (USB to a computer), wouldn't it be possible to wire the Arduino to the Edison via USB (usb on Arduino to J16 (using a MicroA-cable so the Edison becomes host))?

                 

                Do you know of any simple card that has the MCP3204 attached and easy to use with the Edison?

                • 5. Re: Intel Edison and Arduino Uno
                  KurtE

                  I have not tried connecting up a real Arduino to Edison, but have used a USB2AX device which is used to connect up Bioloid servos to the Edison, and it is based on an Atmel Atmega32u2 chip, so yes it is possible.  Not sure if you will need an additional driver or not.  You will also need the adapter cable to convert the USB on the mini to be a host.

                   

                  Don't know about MCP3204, but Sparkfun does sell an analog board for the Edison: https://www.sparkfun.com/products/13046

                  • 6. Re: Intel Edison and Arduino Uno
                    PeterOdd

                    Thank you!
                    Yes I will need a USB microA (male) to USB-A (female) converter so I connect the cable from the Arduino. I hope it works, don't know but if you think it might work I will give it a try at least .

                    Have you worked anything with the analog board you mentioned? I see a user posted comments (on the SparkFun-oage) that (s)he had a C++ library to use it. Do you know if it would be easy to use it using Python?

                     

                    //Sam

                    • 7. Re: Intel Edison and Arduino Uno
                      KurtE

                      Sorry, I have not tried any of the Sparkfun boards out yet. I have been sort of watching as they evolve. 

                      • 8. Re: Intel Edison and Arduino Uno
                        PeterOdd

                        Hi,

                        The experiments yesterday turned out well! When the Arduino Uno is connected via USB to the Edison's J16 using USB Micro-A the Edison becomes host and I can read the output from the Arduino using Python.

                        Since the J16 is occupied controlling the Arduino separate power is needed, a 9V-battery to J21 worked but drained pretty fast so I used a DC-adapter I had at home which gives 12V and ~500mA and connected this to J21.

                         

                        Code to read USB-input:

                        import serial
                        arduino = serial.Serial('/dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_7\
                        543033343735140A141-if00', 115200, timeout=.1)
                        while True:
                            data = arduino.readline()[:-2]
                            if data:
                                print data
                        

                         

                        I suppose the device-id will vary so make sure to check this.

                         

                        A simple Arduino-example to add 1 to a counter each loop:

                        int counter = 0;
                        void setup() {
                          Serial.begin(115200);
                        }
                        void loop() {
                          Serial.println(counter);
                          counter++;
                        }
                        
                        • 9. Re: Intel Edison and Arduino Uno
                          KurtE

                          Glad you got it working.

                           

                          Note: on my machine when I plug an UNO in (currently on Arduino breakout board), it creates the device /dev/ttyACM0

                          Note the 0 may change depending on if you have other such devices, but this appears to be normal as if you search on connecting UNO to RPI, you see posts like:

                          http://www.doctormonk.com/2012/04/raspberry-pi-and-arduino.html

                           

                          Also note: if you want a more specific case where the ACM0 can change, I often then use udev rules to create a specific link.  For example to create a link

                          to USB2AX device I might create a file like: /etc/udev/rules.d/99-usb-serial.rules

                          That contains something like:

                          SUBSYSTEM=="tty", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="06a7", ATTRS{serial}=="74031303437351D02210", SYMLINK+="ttyUSB2AX"

                          Then in your code you can reference /dev/ttyUSB2AX.  You can do the same for the UNO, just use a command like lsusb to find out the details of your device.  I found information on the link: Persistent names for usb-serial devices | HintShop helped me understand this when I was first starting out.

                           

                          Kurt