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.5k 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 @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