1

I wanted to connect an Arduino Nano to either my Pi 3B+ or my Zero W, preferably my Zero. When I connected my Nano to my Pi Zero and ran a simple script with the Python 3 serial library, it didn't work. I did the same with a 3B+, which didn't work either. I then tried connecting a normal Arduino Uno which worked just fine with both the Pi. I tried looking up the issue, but I didn't find any solutions related to connecting a Nano to any kind of Raspberry Pi. I think it might have something to do with the drivers because my Windows laptop recognizes my Nano.

A shortened version of my Python script:

import serial
from time import sleep

string = ""

sleep(2)
arduinoSerialData = serial.Serial('/dev/ttyACM0', 9600)
sleep(2)

#print statements are for debugging

while(True):
    sleep(1)
    arduinoSerialData.write(b's')
    sleep(1.3)
    string = arduinoSerialData.readline().decode('ascii')
    string = string[0]+string[1]+string[2]+string[3]
    f = open("soil.txt","w+")
    f.write(string)
    f.close
    print(string)

I'm using a standard Arduino Uno and Nano with the given serial cable.

Note: I'm using the "Arduino IDE Linux ARM 32 bit" on my Pi to code the Arduino. It recognizes and works with my Uno but not with my Nano, which led me to believe it was a driver issue. 

toyota Supra
  • 209
  • 1
  • 3
  • 6
aklingam
  • 954
  • 3
  • 16
  • This might help: https://raspberrypi.stackexchange.com/questions/96184/rpi3-to-arduino-serial-uart-communication-tutorial. Cheers. – tlfong01 Aug 06 '20 at 05:07
  • @tlfong01 The thing is I can't access the GPIO of the Pi Zero which is what I'm using so I didn't look at any solutions with regards to connecting them using the GPIO. If I don't get any answers, I'll solder on some headers and redo my project. – aklingam Aug 06 '20 at 05:34
  • What on earth is the given serial cable - looks like USB code? What version of Arduino IDE are you using? – Milliways Aug 06 '20 at 05:58
  • @Milliways Here: https://modernelectronics.com.pk/wp-content/uploads/2017/09/2.jpg – aklingam Aug 06 '20 at 06:07
  • @Milliways I'm not sure how the version of my IDE matters but it's 1.8.10 – aklingam Aug 06 '20 at 06:09
  • @aklingam, Ah, you don't need to access RpiZ GPIO pins. You can use an USB to UART adaptor/cable. – tlfong01 Aug 06 '20 at 06:14
  • @tlfong01 Oh Okay, Thanks, I'll order one in a few hours in case somebody has had a similar issue and solved it using the USB Serial Cable. – aklingam Aug 06 '20 at 06:20
  • @aklingam, you can search this forum "UART serial loopback" to find how to set up Rpi onboard and USB serials cable and do loopback testing to make sure python can do serial OK. Beside loop back, you see in my tutorial above, you can use PC Win10 RealTerm or Rpi CuteCom to test the USB serial cable. The 4 or 5 python on board and USB python setup/loopback cables are for Rpi3B newbies. / to continue, ... – tlfong01 Aug 06 '20 at 06:33
  • You may also like to try my advanced version for Rpi to do the following more fancy things: (1) USB serial 0 (/dev/ttyUSB0) loopback to USB serial 1 (/dev/ttyUSB1). The advanced serial loopback demo program link is this: (1) "Rpi3/4 On board Serial and USB serial setup and loopback test": https://penzu.com/p/59cdb6cf. Good luck and cheers. – tlfong01 Aug 06 '20 at 06:35
  • PS, you might find one of my tutorials on multiple Rpi/RpiZ USB serial cables warning that some USB/serial cable might not work for RpiZ. So try Rpi3B first. One more thing before I go, if you have two or three USB to serial cables, you can setup 3 USB serial ports on Rpi and talk to 3 Rpi or nanos at the same time. – tlfong01 Aug 06 '20 at 06:41
  • This Q&A is about how I tested different USB/serial cables and found CH340 and PL2303 are compatible with Rpi3B, but old ***PL2102 are not compatible with Rpi*** (might not work with RpiZ because RpiZ's drivers are not very good. Link: https://raspberrypi.stackexchange.com/questions/96697/how-many-serial-ports-are-on-the-pi-3. Cheers. – tlfong01 Aug 06 '20 at 06:59
  • 1
    @tlfong01 Thank you for all the help! – aklingam Aug 06 '20 at 07:05
  • @aklingam, you are welcome. Cheers. – tlfong01 Aug 06 '20 at 07:16
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/111524/discussion-between-tlfong01-and-aklingam). – tlfong01 Aug 07 '20 at 00:59

1 Answers1

1

The "the given serial cable" is a bog standard miniUSB to USB-A cable. This information belongs in your Question - as does ALL technical detail.

The reference to "Serial Cable" is misleading the cable is USB; the serial interface is on the Arduino - no additional serial interface is needed. (It is technically possible to connect the Pi serial pins to Arduino serial, but far from straightforward, and not necessary).

Similarly the reference to "the GPIO of the Pi Zero" in your Comments is misleading - NO GPIO is involved.

It is unclear what you have connected to what, as the Pi Zero does NOT have a USB-A port (unlike the Pi 3B+) and requires an adapter.

Note the current version is ARDUINO 1.8.13 (some early versions did not support all Arduino models). All Arduino IDE versions have a serial terminal function.

Many Arduino clones DO NOT have the standard USB chips and substitute cheap clones, which are unreliable, and the manufacturer of the official chips has included code to prevent these working with their drivers.

I suggest you first ask on the https://arduino.stackexchange.com/ site to clarify the Arduino issues, then if you still have problems ask a new Question.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Hi, thanks for the answer. I'm really sorry if I confused anyone: the standard USB cable that came with Arduino Uno was called the "Serial Cable" in the book I used to learn Arduino, so I just called it that. I'm pretty certain the Nano I used is not a clone as it worked on windows as I stated in my question. Also, I used a micro A USB to USB A Converter to connect to the Micro B to USB A Cable. Thanks a lot for the help, I just ordered a USB to UART adaptor/cable, so I'll be using that. – aklingam Aug 06 '20 at 09:06
  • @aklingam you obviously did not understand my post. The (unspecified) cable won't help. – Milliways Aug 06 '20 at 09:53
  • @Millways What did you mean by the (unspecified) cable are you talking about the USB to UART adaptor/cable. http://roboticsnepal.com/media/catalog/product/cache/1/image/1800x/040ec09b1e35df139433887a97daa66f/u/s/usb_uart.jpg – aklingam Aug 06 '20 at 10:05
  • @aklingam I don't know how to make this any clearer - you **DON'T** need any "USB to UART adaptor/cable" - indeed it is unclear just what you think this will do or what you plan to connect it to - although if you have an Arduino Pro Mini it might help. Incidentally a picture of a device is meaningless without specifications. – Milliways Aug 06 '20 at 12:41
  • @Millways Then how am I supposed to transfer data from my Arduino to my Pi 0. I had issues with my method of connecting the p 0 I to an Arduino Nano using a micro A USB to USB A Converter to connect to the "bog" Micro B to USB A Cable. Which worked when I used the same code and connected to an Audrino Uno with the "Bog" Micro B cable replaced with a B, it did not work, because I could not find a solution to my issue I'm using an alternate method of communication between the devices that works out for my project that was suggested by tlfong01 because the cable is cheap and I'm not time-bound. – aklingam Aug 06 '20 at 14:21