Python Serial On Pi Pico
| Author | Message | ||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 905 |
Hello all, I am trying to use my VL53L1X laser distance sensor on a Pi Pico. As mentioned (here) I can get it working with Python (supplied with the sensor) but I can't see how to port the Python code to MMBasic (that would be my preference). If anyone is interested I can post the Py code, datasheet etc? (please . . . ?). A second way I have tried is to modify the Py code to output the data to an HC12 (I am reasonably familiar with them). I have copied Lew247's code where he does the same thing. But I get an error. This is my code snippet: from PiicoDev_VL53L1X import PiicoDev_VL53L1X from time import sleep import serial ser = serial.Serial( port='/dev/ttyAMA0', baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) distSensor = PiicoDev_VL53L1X() while True: dist = distSensor.read() # read the distance in millimetres print(str(dist) + " mm") # convert the number to a string and print sleep(1) and the error I get: >>> %Run -c $EDITOR_CONTENT Traceback (most recent call last): File "<stdin>", line 4, in <module> ImportError: no module named 'serial' >>> My intention is that when I can successfully open the port and test it, I'll insert code in the while loop to write to the port. Some questions: - is there a subroutine or library that I need to load for serial (if so where is it and how do I load it?) - how does one write to the port (its not as simple as PRINT #1, "Hello World" is it?) - how does one specify which Com port on the Pico to use? (I'm happy with Com1 on GP0 and GP1 but can use another). Many thanks, Andrew |
||||