USB serial on Raspberry Pi

For general Flowcode discussion that does not belong in the other sections.
RGV250
Posts: 283
http://meble-kuchenne.info.pl
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 32 times

Re: USB serial on Raspberry Pi

Post by RGV250 »

Hi,
Now I have the web pages working I need to look at the serial data again. Do I need to copy the above file, I thought it would install automatically when I updated. According to the updates I am up to date but the version for the CAL_UART installed is V1.0 21/02/2020

Bob

RGV250
Posts: 283
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 32 times

Re: USB serial on Raspberry Pi

Post by RGV250 »

Oops, first own goal was looking at an example for a PIC device which is why I could not see the list of other ports.

Now I have selected the Raspberry Pi I have the drop down list but none of them appear to work. It look like the device is showing up as ttyUSB0 but that is not on the list. In the original project on NodeRED I do not recall having to do anything special so am I missing something.

Regards,
Bob

LeighM
Valued Contributor
Posts: 447
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 81 times
Been thanked: 243 times

Re: USB serial on Raspberry Pi

Post by LeighM »

Hi Bob,
As mentioned previously you will need to create a symlink for one of the serial channels to ttyUSB0
This is done from a Linux command prompt.
For further information see my previous example or search Linux ln command and symlink (symbolic link)
Hope that helps

RGV250
Posts: 283
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 32 times

Re: USB serial on Raspberry Pi

Post by RGV250 »

Hi Leigh,
Do I just enter that in the console or whatever it is called or do I need to add it to the config file?/

Regards,
Bob

LeighM
Valued Contributor
Posts: 447
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 81 times
Been thanked: 243 times

Re: USB serial on Raspberry Pi

Post by LeighM »

You should only need to run the command once in the console

RGV250
Posts: 283
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 32 times

Re: USB serial on Raspberry Pi

Post by RGV250 »

Hi,
I think I have the port moved now, I still cannot see any data but I am wondering if I am using the correct command.
When I plug in to a PC and use a terminal program I get this, the data I am interested in is the 3 lots of 4 on the left.
serial terminal.jpg
serial terminal.jpg (27.54 KiB) Viewed 4112 times
and this is what it looked like on the Raspberry Pi with NodeRED so I am pretty sure I should be using the Receive string option.
Data string.jpg
Data string.jpg (39.66 KiB) Viewed 4112 times
I do not get anything at all, this is what I see.
No input.jpg
No input.jpg (26.5 KiB) Viewed 4112 times
I tried to include the project file just in case I have missed something obvious but it will not let me.

Bob

RGV250
Posts: 283
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 32 times

Re: USB serial on Raspberry Pi

Post by RGV250 »

Project file.
RPI_EcoEyeMonitor_V1_0.fcfx
(28.89 KiB) Downloaded 447 times
Bob

LeighM
Valued Contributor
Posts: 447
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 81 times
Been thanked: 243 times

Re: USB serial on Raspberry Pi

Post by LeighM »

Hi Bob,
I've just had a quick look at your Flowcode and the generated C.
Some thoughts ...

The UART Receive String timeout is limited to 255ms (8 bit variable), hence you need to reduce the 5000.
So I suggest that you reduce to say 200ms and then test the return string for being non-null i.e. InDataString[0] != 0
before you go on to process it.
Maybe check the string length too, just to check you have all of it.

Not sure if your buffer size needs to be a little bigger, due to terminating null or CR/LF etc.
I bit of headroom is always useful :D

RGV250
Posts: 283
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 25 times
Been thanked: 32 times

Re: USB serial on Raspberry Pi

Post by RGV250 »

Hi Leigh,
I really appreciate your support on this.
Originally I had the timeout at 100 and changed it to 5 seconds as I think the device sends data every 4 seconds and thought I might be missing it. I did not think of the byte variable.
I did have the string length at 40 but reduced it as I wondered if it might be waiting for end of message terminator or something.

I do not think it is possible to test as you suggest as generally the first byte will be 0, I could test for a minimum length as I am only interested in the first 3 sets. I wonder if Flowcode is stopping at the first space but even so it would have 4 bytes?

I am looking to see if I can find a simple python example to at least make sure the serial port on the Pi is set up as it should be as even if Flowcode was receiving garbage it should be in the InDataString.

Bob

LeighM
Valued Contributor
Posts: 447
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 81 times
Been thanked: 243 times

Re: USB serial on Raspberry Pi

Post by LeighM »

Hi Bob,
The first character of the string will be '0', but this is 0x30 (or 48 decimal) not 0. Have a look at an ASCII table.
A 100 or 200ms timeout will be fine for a data string every 4 seconds.
Most of the time the receive string will return the null string (first byte 0x00, not the character '0')
If you make the buffer say 40, (looks like minimum needs to be 33+1 for the string null terminator) then you will get the full string
and the timeout will cause a return from the receive string function 100ms after the last character.
So this should synchronise well.

Post Reply