Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Wixel python pyserial no bytes received

I am trying to use serial communication with my wixel. I correctly ran the ‘USB to Serial app’ using the wixel configuration utility, and I also connected to the correct port (ttyACM1, I am using Linux Ubuntu 20.04 LTS).

Here is the code that I wrote. It sends ‘hello’ bytes but I am receiving no bytes back; the readline returned is empty. Please help!

import serial
from time import sleep

ser = serial.Serial('/dev/ttyACM1', baudrate=115200, timeout=1, write_timeout=1)

print(ser.name)  # double check which port is being used

if not ser.isOpen():
    ser.open()
print('Serial port open:', ser.isOpen())

ser.flushInput()
ser.flushOutput()

st = "hello"

# ser.write(b'1')
# print(ser.inWaiting())
# print(ser.read(ser.inWaiting()))

while True:
    try:

        ser.write(st.encode())  # write a string
        sleep(0.25)
        print('input:', st.encode())

        x = ser.inWaiting()
        sleep(0.25)
        print('x:', x)

        out = ser.readline().decode('ascii')
        print('reading output:', out)

    except KeyboardInterrupt:
        ser.close()
        break

Hello.

I am sorry to hear you are having problems with serial communication on your Wixel. What bytes are you expecting to receive back and what device is generating them? Can you list all the devices involved in your setup and how they are connected? Pictures of your setup that show all of your connections might also be helpful.

Also, how did you verify that /dev/ttyACM1 is the correct port?

Brandon

Hi Brandon,

Thank you for your reply. I verified that /dev/ttyACM1 is the correct port by checking what ACM ports exist/don’t exist when I unplug the wixel from my computer. I also checked that when I ran the USB to serial app in the wixel configuration utility, /dev/ttyACM1 showed up, and when it was not running, /dev/ttyACM1 was not there.

I am expecting to receive back the exact same bytes that I send; in this case it would be “hello”. The wixel is the only device in my setup – it is connected via a USB cable directly to my computer and there are no other devices/connections attached to the wixel at all. Am I doing this correctly? I am expecting to get back the same bytes which I send (as per my python script). Suppose I need to receive bytes from specific pins after I connect an analog device to the wixel, do I need to create a new app using the wixel SDK? Thank you very much for your guidance.

The Wixel’s USB-to-Serial App essentially turns the Wixel into a USB-to-TTL serial adapter. So, it will take the serial bytes you send to the virtual COM port and output them from the TX pin (P1_6), and any bytes received by the RX pin (P1_7) will be sent to the virtual COM port.

So, unless you are doing a loop back test (by connecting those two pins together) you will not see the bytes you send out being returned.

It is not clear to me what you mean; can you describe what you are trying to do in more detail? What kind of analog device do you want to connect to the Wixel and what do you want the Wixel to do with that device?

Brandon

The loop test was successful. Suppose I have 6 analog signals that are connected to pins P0_0, P0_1, P0_2, P0_3, P0_4, and P0_5. The ‘analog device’ I am referring to is a pressure sensor, but essentially I have 6 analog signals that need to be read by the wixel and sent to my computer.

All I want the wixel to do is continuously receive the data coming from the pins P0_0, P0_1, P0_2, P0_3, P0_4, and P0_5 and send it back to my computer via serial communication. How can I achieve this? Suppose I connect all the pressure sensors to pins P0_0, …, P0_5. In what way do I connect the TX and RX pins so that I can send a command to the wixel (using a python script) to check what data is coming from the analog pins? I just need to check the data coming from the analog pins using USB to serial communication. Thank you for your help.

The closest pre-made Wixel app we have to what you are describing is probably the test_adc example included with the Wixel Software Development Kit (SDK). The test_adc example reads all 6 analog inputs and reports it to the computer in either CSV format or a bar graph.

The test_adc app reports its results directly to the computer via USB, so you would leave the TX and RX pins disconnected. Additionally, that example will send updated data each time the specified period of time has passed. So, if you want to be able to poll the readings from your Python script, you might try using that example as a starting point to make your own Wixel app. You can find resources for this in the Writing Your Own Wixel App section of the Wixel user’s guide.

Brandon