Uart!

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Uart!

Post by jgu1 »

Hi!
i am playing with seriel wireless TX and RX. Working ok.

In the Component Macro I can send a CHAR and receive the CHAR. And if I say ; "If receiving char, then do something. Working."

I see it is possible to send a number, but how do I receive it, please?

Br Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Uart!

Post by mnf »

Hi Jorgen,

Send number converts the number to an ASCII string and sends that - you could receive that and convert back. Alternatively spilt into bytes and send and recombine..

I can do a simple example if it would help..

Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Uart!

Post by jgu1 »

Hi Martin!

Oh yes, I will be gatefull if you will create a small program for this. Tx and rx. At the moment I use Arduino Nano.

I can att. my programs if it do a difference (tomorrow).

Thank´in advance.

Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Uart!

Post by mnf »

Okay - a small program. This watches UART2 (here a software channel - receive on D2, Tx on D3) - looking for numbers sent as a string (using SendNumber - or in my case putty and a FTDI converter...)
A number of up to 10 digits is converted to a 32 bit unsigned int (so max is 2^32-1) and the string and number 'displayed' by sending to UART1 (another putty terminal on PC)
So '0003' = 3 '1234' = 1234 etc. End of number is any non-numeric character.
uart_demo.fcfx
(14.65 KiB) Downloaded 223 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Uart!

Post by jgu1 »

Hi Martin!

Thank you very much for your effort, but honest I don´t understand the program. I am not so hardcore :roll:

What I trying to make is a wireless remote control. I will send a number, then the receiver reconise this number and activate an output.
It working but I want, as long time I send the number the output is activated on the receiver, and emidiately I stop transmit the output goes low on receiver, (My problem). On this way I can make multible on off output by using the Uart. Hope it make sense and you understand what I mean?

I am not home at the moment, but when I come home (tomorow have the program on another PC) I will att. the program for the transmitter and reveiver I have created.

Thank´s in advance

Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Uart!

Post by mnf »

Hi Jorgen,

Not quite sure I follow what you want - I think it is:

1) Receive a number (say 1)
2) Turn on an output (port 1 in this case)
3) When number finishes port goes off ? or
3) Wait for another command to turn port off?

The above example - the main loop just waits for a string of characters (any of '0'..'9') to have been received (signalled by got_number being set to true by the interrupt) - most of it is concerned with converting this to an integer and displaying the data to the user..
The interrupt routine does most of the work - watches the UART port for data - if it's a number (0..9) it adds it to a 'string' - if it's not a number - then it signals the main program that a number has been received (if the string contains any characters...) by setting got_number to true.

Martin

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Uart!

Post by stefan.erni »

Hi Martin, Hi Jorgen
For some command for the uart I add this "\r\n" on the end.
So the terminalprogram shows a new line for each command. And the most terminalprogram add it automatic.
In the receiving part of my FC progamm I used it for a control.
To use the interrupt I choose the pin from the PIC with uart receive.


It's working to send a command from the terminalprogram like stepa50 (\r\n)

I use this few c command:

Code: Select all

ser_str_command = Left$ (ser_ret_str_bt,5) // get the command without /r/n
ser_str_parameter = Mid$ (ser_ret_str_bt,5,ser_ret_length - 7) // get the parameter
ser_str_parameter_int = StringToInt$ (ser_str_parameter) // convert to integer
You can have a look to the macro Int_uart5 in the program
hterm2.PNG
hterm2.PNG (50.97 KiB) Viewed 5426 times

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Uart!

Post by jgu1 »

Thank's Martin and Stefan

In my testprogram TX send Char 44. In RX I receive the char 44 then CH1 is going on.

But I want CH1 go low again emidiately when I stop transmit.

Is it possible. I would like to add multible channel, to maually be able to control my lawnmover :D

Thank´s in advance

Jorgen.
Attachments
RX.fcfx
(11.8 KiB) Downloaded 184 times
TX.fcfx
(10.23 KiB) Downloaded 191 times

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Uart!

Post by mnf »

Hi Jorgen,

Okay I see what you want to achieve...

Should be fairly straightforward to 'watch' for input (44) and if nothing has been received for a set time then turn off output.

Then if a byte is received - turn on again.

Maybe a 'watchdog' if transmitter goes out of range?

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Uart!

Post by mnf »

So - a simple version.

Here an interrupt on UART Rx watches for character 44. If it is found it turns on the 'output' (here the inbuild LED) - and resets a timer.
The second interrupt (a timer) - increments the time, and if > DELAY (a constant) turns off the LED. Note that the timer runs at ~0.9Hz (I call it bogosecs - so delay of 5 gives (~6) edit - no 5 * .9 = ~4.5 secs output if no further signal received) You could tweak the timer interrupt to run much faster if needed to stop the output very quickly. Edit - my maths is all to pot - 0.9Hz is a cycle of ~1.1seconds.. In my defence - it was a very busy day...

The main loop here just outputs LED OFF or ON (and time on) and isn't really involved at all - apart from a bit of setup.
Watchdog.fcfx
(14.76 KiB) Downloaded 192 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Uart!

Post by jgu1 »

Hi Martin!

Working perfect :D Thank you very much.Now I will try to increace channels output. But Martin what does \r\n mean, has it something to do " go to new line" if writing in display?

Thank´s

Br. Jorgen

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Uart!

Post by mnf »

Glad to hear working okay.

Yes, \r\n is Return Newline - really goes back to the age of teletype. Return moves back to the start of the line and newline advances to the next line. There are several of these 'escape' characters (for example Bell - which should make a sound (originally a bell as on a typewriter))

Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Uart!

Post by jgu1 »

Ok, does it mean when I send a string like this: "\r\n" the display it move to next line, please
?

Tahnk´s.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Uart!

Post by mnf »

Yes..

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Uart!

Post by stefan.erni »

Hi Jorgen, Hi Martin

This "\r\n" is practicel to send to a terminalprogram. It makes you a new line. Most terminalprogram can also make a log file. So you will have there a new line too. With a little more character you can easy log an .CSV file. (a simple excelfile)

There is an another way to send this two ascii code :

regards
Stefan
FC-2020-09-28_17-25-35.png
FC-2020-09-28_17-25-35.png (19.5 KiB) Viewed 5285 times
ASCII-2020-09-28_17-22-03.png
ASCII-2020-09-28_17-22-03.png (715.7 KiB) Viewed 5285 times

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Uart!

Post by jgu1 »

Hi Stefan!

Thank you very much for the tips. :D At the moment I working on a wireless remote control. Later I will definitely play with wireless send string to a display, then I can use your tip.

Br Jorgen

Post Reply