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



  • 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



  • 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 !



  • 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.



  • @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);
    


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



  • @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)
    


  • @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')



  • 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()
    


  • @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 ?



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



  • @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.



  • 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.



  • 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.



Pycom on Twitter