Reading serial string data as integer with Serial DAT

Hello,

I have got a rotary encoder on a Raspberry Pi Pico sending data to my computer via the serial port with Python. I have been able to read this in Touchdesigner via the serial DAT, however the data sent (numbers of the rotary encoder position) is sent as a string.

I presumed the easiest option is to convert this string to an integer in Touchdesigner.

I have a basic proficiency with Python, but am a little stuck on how to best implement the serial callbacks links to the serial input.

The incoming data is just one number (as string) per line / row. I am stripping this back to one row with a Select DAT, but I need to get the data as a integer or float first.

If anyone had an example, I would appreciate it.
Many thanks.

Hi,

I would keep values in the DAT as is and convert them while extracting them for further process when needed.

You can access cell values referencing the op in python : op('table1')[row,column]

If i remember correctly the cell value is automatically casted but you can force its conversion :

op('table1')[row,column] should be the value as integer or float as long it is a numeric value
op('table1')[row,column].val should be the value as string
int(op('table1')[row,column].val) force casting to integer

1 Like

Hello,
If you want to send value obtained by GPIO in raspberry pi, I greatly prefere to use node-red.
– there is an integrated GPIO node (install from palette)
– you can directly send OSC from node-red (install from palette)
– you receive the data in oscin chop (for int and float) or oscin Dat (for string)
There is a very good explanation on how to install node-red on raspberry:
https://nodered.org/docs/getting-started/raspberrypi
I will make a toturial on how to make profit of node-red for TD. At the moment I use it on raspberry for
– a project distributing theater text on 10 different smartphone
– run Dynamixel motors with OSC
– run a VLC video-player with OSC
Jacques


Capture

1 Like

Thanks @jacqueshoepffner,

That looks really interesting. I will definitely explore that.

Thank you @Gallo ,
Your solution was very straight forward and worked well. Thank you for showing me the syntax.
Regards,
Leo

Leo,
For extracting from DAT, there is also the easy solution (without python) to use dattochop Dat.