Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Arduino sends data seriell, how to get them into WiPy ? **SOLVED**

    Scheduled Pinned Locked Moved WiPy 2&3
    wipyseriellarduinorxtxsolved
    13 Posts 5 Posters 4.4k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Hotzenwald
      last edited by livius

      Need help for understanding how to manage my needs.
      I do have an Arduino running some sensors to measure water quality in a pond. Up to now it delivers measuring results serial to an Raspberry Pi. I just connected the USB between both.
      The Raspberry Pi needs too much energy to be driven off grid. I now want to replace it with the WiPy.
      The WiPy 2.0 already does a TCP socket connection to my server using the wifi which reaches the pond area. I can transfer data to the server and i can connect to the wifi.
      Now i need the bridge between the Arduino print serial and the WiPy.
      How would you do this ?
      May i also easily use the USB port or do i have to connect the RX/TX ?
      How con i check if its working as i do not have any more my laptop connected to the WiPy using the USB-Cable ?
      Regards from Germany
      Peter

      V H 3 Replies Last reply Reply Quote 0
      • RobTuDelftR Offline
        RobTuDelft
        last edited by RobTuDelft

        You could use one of the I2C connections between WiPy and Arduino. I think there are several examples around that illustrate this way on interconnecting boards.

        Without data you're just another person with an opinion.
        Hackster | About me

        H 2 Replies Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh
          last edited by robert-hh

          You can use UART and connect TX-RX, RX-TX and GND. Please check first whether the two devices runs at the same supply range of 3.3 V. Arduino devices often run at 5V. If yes, use a level shifter. On WiPy, you can use the UART class for communication, which can be freely configured. If you use the standard UART port, whci is also served by the REPL prompt, you can also sys.stdin.read(), sys.stdin.readline() and sys.stdout.write() at 115200 baud.
          For debugging you could send whatever you get on serial to a socket.
          You could also try implement the sensor code on the WiPy.

          H 1 Reply Last reply Reply Quote 0
          • H Offline
            Hotzenwald @robert-hh
            last edited by

            @robert-hh thanks for your fast answer. I use a couple of shields at the arduino R3 and will not be able to convert this for WiPy.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Hotzenwald @RobTuDelft
              last edited by

              @RobTuDelft had a look at i2C and think this is what i should try. Thanks

              1 Reply Last reply Reply Quote 0
              • H Offline
                Hotzenwald @RobTuDelft
                last edited by

                @RobTuDelft sorry, i am not that familiar with WiPy. I get this Error:
                ImportError: cannot import name I2C
                This is just example code i found

                rom network import WLAN
                import time
                import socket
                from machine import I2C
                import machine
                #configure the I2C bus
                i2c = I2C(0, I2C.MASTER, baudrate=100000)
                i2c.scan() # returns list of slave addresses
                print('I2C ist aktiviert')

                Do i have to prepare something else ?

                1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh
                  last edited by

                  I tested that code snippet on my LoPy and it works.
                  What kind of WiPy and MP version are you using?
                  Look at the output of:

                  import uos
                  uos.uname()
                  
                  H 1 Reply Last reply Reply Quote 0
                  • H Offline
                    Hotzenwald @robert-hh
                    last edited by

                    @robert-hh Thanks. Managed to do a firmware update and now works.
                    (sysname='WiPy', nodename='WiPy', release='1.6.8.b1', version='v1.8.6-504-gff1098f6 on 2017-03-13', machine='WiPy with ESP32')

                    L 1 Reply Last reply Reply Quote 0
                    • V Offline
                      vruizvil @Hotzenwald
                      last edited by vruizvil

                      @Hotzenwald
                      My code to read Arduino Serial port, works fine for me.

                      import machine
                      
                      #initialize serial port on P3 P4 (Tx Rx)
                      uart1=machine.UART(1, 115200)
                      
                      def serialrecv(uartport):
                        #read the length of the data, letter by letter until we reach EOL
                        length_str = ''
                        char = uartport.read(1)
                        while char.decode() != '\r':
                           length_str += char.decode()
                           char = uartport.read(1) 
                        return length_str
                      
                      while (True):
                          #read the serial message
                          serialdata=serialrecv(uart1)
                          print(serialdata)
                      
                      1 Reply Last reply Reply Quote 0
                      • L Offline
                        livius @Hotzenwald
                        last edited by

                        @Hotzenwald
                        woow 1.6.8?
                        @daniel i do not see any info about this?

                        think about people first, then computers

                        1 Reply Last reply Reply Quote 0
                        • V Offline
                          vruizvil @Hotzenwald
                          last edited by

                          @Hotzenwald Hi!!
                          I use Lopy. In my project, connecting from lopy P3(TX1) to arduino PIN0(RX) and lopy P4(RX1) to arduino uno PIN1(TX) it works. You need initialize uart1 whit the same baud rate than arduino.
                          Here my arduino code to read DHT11 temperature sensor.

                          #ARDUINO CODE TO READ DHT11 VALUES AND SEND IT TO SERIAL ON JSON FORMAT
                          include <SimpleDHT.h>
                          // for DHT11, 
                          //      VCC: 5V or 3V
                          //      GND: GND
                          //      DATA: 2
                          int pinDHT11 = 2;
                          SimpleDHT11 dht11;
                          
                          void setup() {
                            Serial.begin(115200);
                          }
                          
                          void loop() {
                             byte temperature = 0;
                            byte humidity = 0;
                            if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) {
                              Serial.print("Read DHT11 failed.");
                              return;
                            }
                            Serial.print("{\"T\":"); Serial.print((int)temperature); Serial.print(",");
                            Serial.print("\"H\":"); Serial.print((int)humidity); Serial.println("}");
                            
                            // DHT11 sampling rate is 2HZ.
                            delay(2000);
                          
                          1 Reply Last reply Reply Quote 0
                          • RobTuDelftR Offline
                            RobTuDelft
                            last edited by

                            I think indeed a communication through UART is the best option. Also see the tutorial I wrote here: https://forum.pycom.io/topic/978/lopy-arduino-serial-communication.

                            Hope that helps.

                            Without data you're just another person with an opinion.
                            Hackster | About me

                            1 Reply Last reply Reply Quote 0
                            • H Offline
                              Hotzenwald @Hotzenwald
                              last edited by

                              solved.
                              The problems i had has been level shifter dependend. I used another one and UART started to work.
                              Another trap has been a misunderstanding in PIN numbering and PIN layout. When i just looked at WiPy pinout without paying attention to expansion board i noticed, that i used the wrong PINs. Now i count from left side, starting with 0 and figured out which PINs i do have to use.
                              Now it works like a charm.
                              Thanks for all your help !

                              1 Reply Last reply Reply Quote 0

                              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                              With your input, this post could be even better đź’—

                              Register Login
                              • 1 / 1
                              • First post
                                Last post

                              Pycom on Twitter

                              Pycom