Communicate from PICO to RPi
Hi,
I am trying to get the ADC values to go from my pico board to an RPI running python.
I have tried both UART and serial, neither has worked.
Could someone give me a code snippet of any sort of communication from pico to RPI? Ideally only in python.
Thanks
Androo
I am trying to get the ADC values to go from my pico board to an RPI running python.
I have tried both UART and serial, neither has worked.
Could someone give me a code snippet of any sort of communication from pico to RPI? Ideally only in python.
Thanks
Androo
Re: Communicate from PICO to RPi
I tried this:
https://www.google.com/search?q=communi ... 20to%20RPI
And got this:
https://medium.com/geekculture/serial-c ... c0ba97c7dc
Plus several other hits.
Connecting the Pico to a Pi via USB and opening the serial interface probably couldn't be simpler. If it's not working then describe exactly how you are doing it in case someone can spot a reason it won't work.
https://www.google.com/search?q=communi ... 20to%20RPI
And got this:
https://medium.com/geekculture/serial-c ... c0ba97c7dc
Plus several other hits.
Connecting the Pico to a Pi via USB and opening the serial interface probably couldn't be simpler. If it's not working then describe exactly how you are doing it in case someone can spot a reason it won't work.
Hmm. What can I put here?
Re: Communicate from PICO to RPi
If you are running a standard release of MicroPython on your Pico board then Brian Pugh's Belay module running on your RPi will accomplish this. https://github.com/BrianPugh/belay
There is a code sample for exactly this purpose in the supplied examples. https://github.com/BrianPugh/belay/blob ... dc/main.py
Re: Communicate from PICO to RPi
Following this thread, I am able to get the code to run on the Pico, (when I test it by running it in thonny I get "NO data", but that is expected as I am not sending any data to it through code). Anywho, I saved the code as main.py, closed thonny, and rebooted the pico.
running this code on VScode on my PC connected to the pico through usb
Code: Select all
import time
import os
serial_connected = 0
if os.path.exists('/dev/ttyACM0') == True:
import serial
ser = serial.Serial('/dev/ttyACM0', 115200)
serial_connected = 1
time.sleep(1)
while True:
time.sleep(2)
for x in range (0,5):
command = str(x) + "\n"
ser.write(bytes(command.encode('ascii')))
if ser.inWaiting() > 0:
pico_data = ser.readline()
pico_data = pico_data.decode("utf-8","ignore")
print (pico_data[:-2])
Returns this error:
Code: Select all
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/name/Documents/Python Scripts/test.py"
Traceback (most recent call last):
File "c:\Users\name\Documents\Python Scripts\test.py", line 15, in <module>
ser.write(bytes(command.encode('ascii')))
NameError: name 'ser' is not defined. Did you mean: 'set'?
For some reason '/dev/ttyACM0' is not accessible, but I don't understand why.
Re: Communicate from PICO to RPi
I had tried this before but i'll summarize my efforts betterame wrote: ↑Wed Feb 08, 2023 8:12 amI tried this:
https://www.google.com/search?q=communi ... 20to%20RPI
And got this:
https://medium.com/geekculture/serial-c ... c0ba97c7dc
Plus several other hits.
Connecting the Pico to a Pi via USB and opening the serial interface probably couldn't be simpler. If it's not working then describe exactly how you are doing it in case someone can spot a reason it won't work.
For the USB route:
I had seen this page previously but I am unable to get robot or rUSB to import. Whenever I go to look up those packages on thonny I find nothing.
I am doing Thonny -> Tools -> Manage Packages -> type "Rusb" in the bar at the top, it returns
Code: Select all
Could not find the package from PyPI.
Please check your spelling!
For context, I am testing this on a RPI4.
First, for connections,
RPI pin 9 -> Pico Pin 8 (GND -> GND)
RPI pin 8 -> Pico Pin 7 (TX -> RX)
RPI pin 10 -> Pico pin 6 (RX -> TX)
I have gone into
Code: Select all
sudo nano /boot/config.txt
Code: Select all
enable_uart=1
UART(0, baudrate=115200, bits=8, parity=None, stop=1, tx=0, rx=1, txbuf=256, rxbuf=256, timeout=0, timeout_char=1, invert=None)
<class 'bytes'>
b'\x00'
<class 'str'>
>>
running this code:
Code: Select all
# sender.py
import time
import serial
ser = serial.Serial(
port='/dev/ttyS0', # Change this according to connection methods, e.g. /dev/ttyUSB0
baudrate = 115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
msg = ""
i = 0
while True:
i+=1
print("Counter {} - Hello from Raspberry Pi".format(i))
ser.write('hello'.encode('utf-8'))
time.sleep(2)
Code: Select all
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/name/Documents/Python Scripts/test.py"
Traceback (most recent call last):
File "c:\Users\name\Documents\Python Scripts\test.py", line 4, in <module>
ser = serial.Serial(
File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\site-packages\serial\serialwin32.py", line 33, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\site-packages\serial\serialutil.py", line 244, in __init__
self.open()
File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\site-packages\serial\serialwin32.py", line 64, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port '/dev/ttyS0': FileNotFoundError(2, 'The system cannot find the path specified.', None, 3)
Re: Communicate from PICO to RPi
So to test this I changed my testing setup from the other replies.B.Goode wrote: ↑Wed Feb 08, 2023 9:47 am
If you are running a standard release of MicroPython on your Pico board then Brian Pugh's Belay module running on your RPi will accomplish this. https://github.com/BrianPugh/belay
There is a code sample for exactly this purpose in the supplied examples. https://github.com/BrianPugh/belay/blob ... dc/main.py
The pico is connected to the PI through a USB cable. This was tested on USB 2.0 and 3.0.
Running the code from here: https://github.com/BrianPugh/belay/blob ... dc/main.py
I get this error message
Code: Select all
pi@rp4:~/UART $ python testcode.py
Traceback (most recent call last):
File "/home/pi/UART/testcode.py", line 10, in <module>
device = belay.Device(args.port)
File "/home/pi/.local/lib/python3.9/site-packages/belay/device.py", line 253, in __init__
self._connect_to_board(**self._board_kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/belay/device.py", line 332, in _connect_to_board
self._board = Pyboard(**kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/belay/pyboard.py", line 357, in __init__
raise PyboardError("failed to access " + device)
belay.pyboard.PyboardError: failed to access /dev/ttyUSB0
Code: Select all
PS C:\Users\name> & C:/Users/fisch/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/name/Documents/Python Scripts/test.py"
Traceback (most recent call last):
File "c:\Users\name\Documents\Python Scripts\test.py", line 10, in <module>
device = belay.Device(args.port)
File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\site-packages\belay\device.py", line 253, in __init__
self._connect_to_board(**self._board_kwargs)
File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\site-packages\belay\device.py", line 332, in _connect_to_board
self._board = Pyboard(**kwargs)
File "C:\Users\name\AppData\Local\Programs\Python\Python310\lib\site-packages\belay\pyboard.py", line 357, in __init__
raise PyboardError("failed to access " + device)
belay.pyboard.PyboardError: failed to access /dev/ttyUSB0
Re: Communicate from PICO to RPi
Regarding the proposed Belay solution -
I am pretty certain that a usb-connected micropython Pico will not present itself to a Windows system as '/dev/ttyUSB0'
And I am not in front of a RasPiOS + Pico combination right now, but '/dev/ttyUSB0' doesn't look right for a RasPiOS installation either.
androo4u wrote: ↑Wed Feb 08, 2023 3:54 pm
The pico is connected to the PI through a USB cable. This was tested on USB 2.0 and 3.0.
Running the code from here: https://github.com/BrianPugh/belay/blob ... dc/main.py
I get this error message
I also tried running it on my PC for posterity. I get the same error:Code: Select all
belay.pyboard.PyboardError: failed to access /dev/ttyUSB0
Code: Select all
belay.pyboard.PyboardError: failed to access /dev/ttyUSB0
I am pretty certain that a usb-connected micropython Pico will not present itself to a Windows system as '/dev/ttyUSB0'
And I am not in front of a RasPiOS + Pico combination right now, but '/dev/ttyUSB0' doesn't look right for a RasPiOS installation either.
Re: Communicate from PICO to RPi
B.Goode wrote: ↑Wed Feb 08, 2023 4:12 pmRegarding the proposed Belay solution -
androo4u wrote: ↑Wed Feb 08, 2023 3:54 pm
The pico is connected to the PI through a USB cable. This was tested on USB 2.0 and 3.0.
Running the code from here: https://github.com/BrianPugh/belay/blob ... dc/main.py
I get this error message
I also tried running it on my PC for posterity. I get the same error:Code: Select all
belay.pyboard.PyboardError: failed to access /dev/ttyUSB0
Code: Select all
belay.pyboard.PyboardError: failed to access /dev/ttyUSB0
I am pretty certain that a usb-connected micropython Pico will not present itself to a Windows system as '/dev/ttyUSB0'
And I am not in front of a RasPiOS + Pico combination right now, but '/dev/ttyUSB0' doesn't look right for a RasPiOS installation either.
I have also tried ttyS0 - ttys4 if that can help? I don't know what other addresses exist.
Re: Communicate from PICO to RPi
How do you normally interact with your Pico for development? What device id do you use then? What tool do you use on the RPi for communication?
What linux-like OS are you running on the RPi board. (Which I guess is an RPi4b?)
Re: Communicate from PICO to RPi
its noobs running on RPI4b.
For pico I flash it and REPL with it through thonny. I don't know what device ID thonny uses.
Re: Communicate from PICO to RPi
If you run ls /dev does it show ttyACM0 or maybe ttyACM1 ?androo4u wrote: ↑Wed Feb 08, 2023 3:25 pm
Following this thread, I am able to get the code to run on the Pico, (when I test it by running it in thonny I get "NO data", but that is expected as I am not sending any data to it through code). Anywho, I saved the code as main.py, closed thonny, and rebooted the pico.
running this code on VScode on my PC connected to the pico through usbCode: Select all
import time import os serial_connected = 0 if os.path.exists('/dev/ttyACM0') == True: import serial ser = serial.Serial('/dev/ttyACM0', 115200) serial_connected = 1 time.sleep(1) while True: time.sleep(2) for x in range (0,5): command = str(x) + "\n" ser.write(bytes(command.encode('ascii'))) if ser.inWaiting() > 0: pico_data = ser.readline() pico_data = pico_data.decode("utf-8","ignore") print (pico_data[:-2])
Returns this error:
Code: Select all
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/name/Documents/Python Scripts/test.py" Traceback (most recent call last): File "c:\Users\name\Documents\Python Scripts\test.py", line 15, in <module> ser.write(bytes(command.encode('ascii'))) NameError: name 'ser' is not defined. Did you mean: 'set'?
For some reason '/dev/ttyACM0' is not accessible, but I don't understand why.
Re: Communicate from PICO to RPi
NOOBS is a deprecated Installer, not an Operating System.
Ref: https://www.raspberrypi.com/documentati ... ing-system
NOOBS, or New Out Of the Box Software to give it its full name, was an SD card-based installer for Raspberry Pi computers; we no longer recommend or support using NOOBS. Going forward, please use Raspberry Pi Imager.
Thonny reports the device it is connecting to at the bottom right of the screen. You might need to click on the dialog box at the corner to display the details.
Last edited by B.Goode on Wed Feb 08, 2023 4:45 pm, edited 1 time in total.
Re: Communicate from PICO to RPi
I get COM5 as additional info when I click the pico at the bottom right of thonny.
RPI is running Raspberry Pi OS (32 bit) released 2022-09-22.
Re: Communicate from PICO to RPi
Where would I run ls /dev/? It just spits an error that it doesnt exist when I run it on my PC.gordon77 wrote: ↑Wed Feb 08, 2023 4:35 pmIf you run ls /dev does it show ttyACM0 or maybe ttyACM1 ?androo4u wrote: ↑Wed Feb 08, 2023 3:25 pm
Following this thread, I am able to get the code to run on the Pico, (when I test it by running it in thonny I get "NO data", but that is expected as I am not sending any data to it through code). Anywho, I saved the code as main.py, closed thonny, and rebooted the pico.
running this code on VScode on my PC connected to the pico through usbCode: Select all
import time import os serial_connected = 0 if os.path.exists('/dev/ttyACM0') == True: import serial ser = serial.Serial('/dev/ttyACM0', 115200) serial_connected = 1 time.sleep(1) while True: time.sleep(2) for x in range (0,5): command = str(x) + "\n" ser.write(bytes(command.encode('ascii'))) if ser.inWaiting() > 0: pico_data = ser.readline() pico_data = pico_data.decode("utf-8","ignore") print (pico_data[:-2])
Returns this error:
Code: Select all
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/name/Documents/Python Scripts/test.py" Traceback (most recent call last): File "c:\Users\name\Documents\Python Scripts\test.py", line 15, in <module> ser.write(bytes(command.encode('ascii'))) NameError: name 'ser' is not defined. Did you mean: 'set'?
For some reason '/dev/ttyACM0' is not accessible, but I don't understand why.
Re: Communicate from PICO to RPi
I would run it on a linux-like Operating System, not MicroSoft Windows. Windows doesn't normally name devices like that. The headline question was "Communicate from PICO to RPi", and your RPi is unlikely to be running Windows.
Re: Communicate from PICO to RPi
Apologies. I am going between my PC and my PI to debug.
Doing ls /dev/ outputs this, to be clear, the pico is connected through USB 3.0
Code: Select all
pi@rp4:~ $ ls /dev/
autofs loop2 ram12 tty14 tty4 tty8 vcsm-cma
block loop3 ram13 tty15 tty40 tty9 vcsu
btrfs-control loop4 ram14 tty16 tty41 ttyACM0 vcsu1
bus loop5 ram15 tty17 tty42 ttyAMA0 vcsu2
cachefiles loop6 ram2 tty18 tty43 ttyprintk vcsu3
cec0 loop7 ram3 tty19 tty44 uhid vcsu4
cec1 loop-control ram4 tty2 tty45 uinput vcsu5
char mapper ram5 tty20 tty46 urandom vcsu6
console media0 ram6 tty21 tty47 v4l vcsu7
cuse media1 ram7 tty22 tty48 vchiq vga_arbiter
disk media2 ram8 tty23 tty49 vcio vhci
dma_heap media3 ram9 tty24 tty5 vc-mem video10
dri mem random tty25 tty50 vcs video11
fd mmcblk0 rfkill tty26 tty51 vcs1 video12
full mmcblk0p1 serial tty27 tty52 vcs2 video13
fuse mmcblk0p2 serial1 tty28 tty53 vcs3 video14
gpiochip0 mqueue shm tty29 tty54 vcs4 video15
gpiochip1 net snd tty3 tty55 vcs5 video16
gpiomem null stderr tty30 tty56 vcs6 video18
hwrng port stdin tty31 tty57 vcs7 video19
i2c-20 ppp stdout tty32 tty58 vcsa video20
i2c-21 ptmx tty tty33 tty59 vcsa1 video21
initctl ptp0 tty0 tty34 tty6 vcsa2 video22
input pts tty1 tty35 tty60 vcsa3 video23
kmsg ram0 tty10 tty36 tty61 vcsa4 video31
log ram1 tty11 tty37 tty62 vcsa5 watchdog
loop0 ram10 tty12 tty38 tty63 vcsa6 watchdog0
loop1 ram11 tty13 tty39 tty7 vcsa7 zero
Re: Communicate from PICO to RPi
Presumably that is on a Microsoft Windows PC.
So to run the Belay ADC sample you would need something like
Code: Select all
python Scripts/test.py -p COM5
Code: Select all
python Scripts/test.py -p "COM5"
Re: Communicate from PICO to RPi
appears OK
mine works OK with this output
NO data
NO data
adc ch: 0 : 1056
adc ch: 1 : 928
adc ch: 2 : 928
adc ch: 3 : 8145
Temp: 12.06379
NO data
adc ch: 0 : 1024
adc ch: 1 : 944
adc ch: 2 : 944
adc ch: 3 : 8129
Temp: 12.06379
NO data
adc ch: 0 : 1024
mine works OK with this output
NO data
NO data
adc ch: 0 : 1056
adc ch: 1 : 928
adc ch: 2 : 928
adc ch: 3 : 8145
Temp: 12.06379
NO data
adc ch: 0 : 1024
adc ch: 1 : 944
adc ch: 2 : 944
adc ch: 3 : 8129
Temp: 12.06379
NO data
adc ch: 0 : 1024
Re: Communicate from PICO to RPi
Under RasPiOS the device representing your MicroPython Pico will be /dev/ttyACM0 devices. Again, Thonny will probably autodetect this and report it in the same location.
Again, you can pass this to the test script as an argument something like
Code: Select all
python testcode.py -p /dev/ttyACM0
Re: Communicate from PICO to RPi
Some good news! this code works!gordon77 wrote: ↑Wed Feb 08, 2023 4:35 pmIf you run ls /dev does it show ttyACM0 or maybe ttyACM1 ?androo4u wrote: ↑Wed Feb 08, 2023 3:25 pm
Following this thread, I am able to get the code to run on the Pico, (when I test it by running it in thonny I get "NO data", but that is expected as I am not sending any data to it through code). Anywho, I saved the code as main.py, closed thonny, and rebooted the pico.
running this code on VScode on my PC connected to the pico through usbCode: Select all
import time import os serial_connected = 0 if os.path.exists('/dev/ttyACM0') == True: import serial ser = serial.Serial('/dev/ttyACM0', 115200) serial_connected = 1 time.sleep(1) while True: time.sleep(2) for x in range (0,5): command = str(x) + "\n" ser.write(bytes(command.encode('ascii'))) if ser.inWaiting() > 0: pico_data = ser.readline() pico_data = pico_data.decode("utf-8","ignore") print (pico_data[:-2])
Returns this error:
Code: Select all
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/name/Documents/Python Scripts/test.py" Traceback (most recent call last): File "c:\Users\name\Documents\Python Scripts\test.py", line 15, in <module> ser.write(bytes(command.encode('ascii'))) NameError: name 'ser' is not defined. Did you mean: 'set'?
For some reason '/dev/ttyACM0' is not accessible, but I don't understand why.
My output reads like this:
Code: Select all
pi@rp4:~/usb $ python usb_test.py
Temperature: 17.2C
Temperature: 17.2C
Temperature: 17.7C
Temperature: 17.7C
Temperature: 17.2C
Temperature: 17.7C
Temperature: 17.2C
Temperature: 17.7C
Temperature: 17.2C
Temperature: 17.7C
Temperature: 17.7C
Temperature: 17.2C
Temperature: 17.2C
Temperature: 17.7C
Temperature: 17.2C
Temperature: 17.7C
Temperature: 17.7C
Temperature: 17.7C
In any case, could you help me understand it a bit better? I don't understand where its calling the ADC. I would like to modify the code to read my the value on pin 26, and print the voltage, but I dont see any pins.
Thank you immensely B_goode and Ame for your help. Sorry I couldn't get your implementation to work.
Re: Communicate from PICO to RPi
Later... Sitting in front of an RPi4B running RasPiOS and a Pico running micropython. Checking the belay solution I proposed.
Checking with dmesg after connecting the usb cable to the Pico -
So the device that RasPiOS has assigned is /dev/ttyACM0
Using that information to pass the correct port argument to the belay adc example script -
The almost magical feature of this solution is that it needs no custom code running on the Pico other than flashing a standard build of micropython.
Checking with dmesg after connecting the usb cable to the Pico -
Code: Select all
[ 979.688125] usb 1-1.3: new full-speed USB device number 4 using xhci_hcd
[ 979.795560] usb 1-1.3: New USB device found, idVendor=2e8a, idProduct=0005, bcdDevice= 1.00
[ 979.795589] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 979.795606] usb 1-1.3: Product: Board in FS mode
[ 979.795619] usb 1-1.3: Manufacturer: MicroPython
[ 979.795632] usb 1-1.3: SerialNumber: e660d051135e2636
[ 979.808315] cdc_acm 1-1.3:1.0: ttyACM0: USB ACM device
Using that information to pass the correct port argument to the belay adc example script -
Code: Select all
pi@rpitest64:~/belay/belay/examples/03_read_adc $ python main.py -p /dev/ttyACM0
Temperature: 19.1C
Temperature: 19.6C
Temperature: 22.4C
Temperature: 22.4C
Temperature: 20.5C
Temperature: 19.1C
Temperature: 19.1C
Re: Communicate from PICO to RPi
To allow you to make progress in case @gordon77 isn't around this evening.
The reason you don't see Pin numbers used in gordon's example, or the belay example, is that MicroPython is pre-configured to use machine.ADC(0) as a reference to reading from GP26, similarly ADC(1)/GP27, and ADC(2)/GP28. See Section 3.3 of the Raspberry Pi micropython documentation. https://datasheets.raspberrypi.com/pico ... on-sdk.pdf
machine.ADC(4) returns the adc value of the internal temperature sensor which is being used by both example scripts. There is no physical GPIO pin associated with that adc channel.
So to use GP26, change the script to use machine.ADC(0).
Last edited by B.Goode on Wed Feb 08, 2023 9:49 pm, edited 1 time in total.
Re: Communicate from PICO to RPi
In the pico code adc0 is pin26androo4u wrote: ↑Wed Feb 08, 2023 9:07 pmSome good news! this code works!gordon77 wrote: ↑Wed Feb 08, 2023 4:35 pmIf you run ls /dev does it show ttyACM0 or maybe ttyACM1 ?androo4u wrote: ↑Wed Feb 08, 2023 3:25 pm
Following this thread, I am able to get the code to run on the Pico, (when I test it by running it in thonny I get "NO data", but that is expected as I am not sending any data to it through code). Anywho, I saved the code as main.py, closed thonny, and rebooted the pico.
running this code on VScode on my PC connected to the pico through usbCode: Select all
import time import os serial_connected = 0 if os.path.exists('/dev/ttyACM0') == True: import serial ser = serial.Serial('/dev/ttyACM0', 115200) serial_connected = 1 time.sleep(1) while True: time.sleep(2) for x in range (0,5): command = str(x) + "\n" ser.write(bytes(command.encode('ascii'))) if ser.inWaiting() > 0: pico_data = ser.readline() pico_data = pico_data.decode("utf-8","ignore") print (pico_data[:-2])
Returns this error:
Code: Select all
PS C:\Users\name> & C:/Users/name/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/name/Documents/Python Scripts/test.py" Traceback (most recent call last): File "c:\Users\name\Documents\Python Scripts\test.py", line 15, in <module> ser.write(bytes(command.encode('ascii'))) NameError: name 'ser' is not defined. Did you mean: 'set'?
For some reason '/dev/ttyACM0' is not accessible, but I don't understand why.
My output reads like this:(a bit chilly so I assume this isnt fully correct tbh).Code: Select all
pi@rp4:~/usb $ python usb_test.py Temperature: 17.2C Temperature: 17.2C Temperature: 17.7C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.7C Temperature: 17.2C Temperature: 17.2C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.7C Temperature: 17.7C
In any case, could you help me understand it a bit better? I don't understand where its calling the ADC. I would like to modify the code to read my the value on pin 26, and print the voltage, but I dont see any pins.
Thank you immensely B_goode and Ame for your help. Sorry I couldn't get your implementation to work.
adc0 = machine.ADC(0)
And this is where it reads it...
print("adc ch: " + str(ch[0]) + " : " + str(adc0.read_u16()))
Re: Communicate from PICO to RPi
gordon77 wrote: ↑Wed Feb 08, 2023 9:49 pmIn the pico code adc0 is pin26androo4u wrote: ↑Wed Feb 08, 2023 9:07 pmSome good news! this code works!
My output reads like this:(a bit chilly so I assume this isnt fully correct tbh).Code: Select all
pi@rp4:~/usb $ python usb_test.py Temperature: 17.2C Temperature: 17.2C Temperature: 17.7C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.7C Temperature: 17.2C Temperature: 17.2C Temperature: 17.7C Temperature: 17.2C Temperature: 17.7C Temperature: 17.7C Temperature: 17.7C
In any case, could you help me understand it a bit better? I don't understand where its calling the ADC. I would like to modify the code to read my the value on pin 26, and print the voltage, but I dont see any pins.
Thank you immensely B_goode and Ame for your help. Sorry I couldn't get your implementation to work.
adc0 = machine.ADC(0)
And this is where it reads it...
print("adc ch: " + str(ch[0]) + " : " + str(adc0.read_u16()))
I see, thanks, I was able to get it working more or less.
One more problem; I seem to having some trouble getting consistent outputs;
Code: Select all
python usb_test.py
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05559167
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05639734
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05317464
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05559167
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05478599
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
adc ch: 0 : 0.05398031
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
NO data
this also happens running to stock code:
Code: Select all
python git.py
NO data
adc ch: 0 : 1232
adc ch: 1 : 1072
adc ch: 2 : 1056
adc ch: 3 : 8081
Temp: 23.29925
NO data
adc ch: 0 : 1072
adc ch: 1 : 1072
adc ch: 2 : 1056
adc ch: 3 : 7985
Temp: 22.8311
NO data
adc ch: 0 : 1136
adc ch: 1 : 1088
adc ch: 2 : 1056
adc ch: 3 : 8001
Temp: 22.8311