Many Raspberry Pi Pico W project in microPython require the logging of sensor data. With these log files, we need a convenient way to transfer the data from the Pi Pico to a desktop PC. In earlier lessons, we showed how to log data to the Pi Pico flash memory. In today’s lesson we show how to transfer those log files to your PC. This is the code we developed in the video lesson.
In this video lesson we show how we can send and receive data between the Raspberry Pi Pico W, and your PC. We will be running python on the PC, and we will exchange data using the UDP protocol. UDP is simple, and a very reliable way to send data packets back and forth. In this example, we will be demonstrating a simple Client Server relationship between the Pi Pico and PC using UDP over WiFi.
For your convenience, this is the “Server” software you will run on the Pi Pico.
# Optional: Pause for a short period to prevent overwhelming the client
time.sleep(1)
Notice that the above code wants to load a “secrets” file that contain your WiFi name, and password
You should edit the code below with your WiFi username and your password, and then save the file in the Pi Pico lib folder, with the name secrets.py (don’t forget the .py)
1
2
SSID="YOUR WIFI NAME"
PASSWORD="YOUR WIFI PASSWORD"
Now, on the PC side, you will run your client, which will be run in Python. Here is the client software:
In this Video Lesson I will teach you how to use echolocation to measure distances. We will use the HC-SR04 Ultrasonic Sensor, and will use the Raspberry Pi Pico W. We will explain how echolocation works, and show you how the sensor works. We will do the math, and then create the code for making measurements.
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
importmachine
importtime
TRIG_PIN=16
ECHO_PIN=17
TRIG=machine.Pin(TRIG_PIN,machine.Pin.OUT)
ECHO=machine.Pin(ECHO_PIN,machine.Pin.IN)
defdistance():
TRIG.low()
time.sleep_us(2)
TRIG.high()
time.sleep_us(10)
TRIG.low()
while(ECHO.value()==0):
pass
time1=time.ticks_us()
while(ECHO.value()==1):
pass
time2=time.ticks_us()
pingTime=time.ticks_diff(time2,time1)/2
d=.0343*pingTime
returnd
whileTrue:
dist=distance()
print("Distance to Target: ",dist," cm")
time.sleep_ms(250)
Making The World a Better Place One High Tech Project at a Time. Enjoy!
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok