Optimize rx bytes

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Optimize rx bytes

Post by Ferla »

Hello guys
Perhaps you can help me to obtain and improve the following macro.
Occasionally I encounter a problem on my flow code and I think it's the following macro. Very simple, I receive string Uart that I manage through buffer then the whole thing goes to the following macro that manages the assignment of the variables, this to turn on a led strip ws2812. Everything works but random are lit some random LEDs and always ramdom the LEDs turn on with an incorrect color.
Thanks any help will be appreciated
Ferla
Attachments
RicString.fcm
(17.22 KiB) Downloaded 199 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: Optimize rx bytes

Post by mnf »

Hi Ferla,

Are you any further ahead now? What do you mean by 'random' pixels ? (Do you get (genuinely) random pixels set, or are the results consistent with the same pixels set each time with the same input?)

Can you give some examples of input that work correctly, and some that fail?

Martin

Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Re: Optimize rx bytes

Post by Ferla »

Hi Martin dear friend
I knew I counted on you.
Maybe I expressed myself badly.
Send the same string every 500ms.The string is as follows "<A022005255000000>." After checking the initial "<" and the final ">" character inside the flowcode step. To the macro I attached last time, I assign as per your suggestion old post the bytes to the following variables so divided :
Var Byte Description
dinL "A" Start
Led "022" Lighting Led n.22 along the led strip
LedGr "005" Ignition n. 5 Leds after Led n.22
R "255" Color of the red leds because the other variables G and B are at zero
G "000"
B "000
As mentioned the LEDs turn on correctly for several times but often random the color changes from red to green to blue etc. In addition to this problem it also happens that when the string is received, only one LED is lit along the LED strip in a random position , which is also randomly colored. It is more difficult to explain it would be much easier to see it, I hope I was clear. E' strange I have no idea why it happens and above all difficult to understand why random.
Thank you very much Ferla

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: Optimize rx bytes

Post by mnf »

Hi Ferla,

I'm not sure I have many answers for you but.. several questions instead :)

1) What microcontroller are you running this on (if its an Arduino you may be running out of memory if you have an LED strip of > 300 leds) (I wrote a program that outputs to an LED strip using the FC WS2812 component and it works well with 120 LEDs (360 bytes) 300 LEDs (900 bytes) is probably pushing it...The Arduino only has 1024 bytes RAM)

2) Your code jumps ahead if it hits an error
test.png
(18.66 KiB) Downloaded 2476 times
- this may not give the result you are expecting if, for example, the circular buffer is empty - any subsequent reads will also be starting at the wrong place in the string and also be wrong.

3) Rather than use a shift I would simply set the LEDs using a loop
test2.png
(11.65 KiB) Downloaded 2476 times
(the shift (assuming the LED bar component does the same as the FC standard component) will shift all the bytes in the LED strip - so will be at least rather inefficient)

I'd pull the 'ReadInt' from circular buffer into a separate macro - it will give you more readable code and any changes to the code only need to be made once (and debugged once)

4) What output do you get from the serial monitor? Is the data correct here and the display incorrect or are both wrong?

Martin

Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Re: Optimize rx bytes

Post by Ferla »

Hi Martin
I notice a strange thing, when I empty the Flush Buffer the rest and remains the final character ">" why?
This could cause problems in rereading the new string? What do you think about it?
This evening I do further tests and I'll let you know what Uart is.

A greeting
Ferla
Attachments
Byte Buffer.jpg
Byte Buffer.jpg (182.45 KiB) Viewed 4485 times
Flush Buffer.jpg
Flush Buffer.jpg (187.82 KiB) Viewed 4485 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: Optimize rx bytes

Post by mnf »

Any results from the UART output??

The FlushBuffer doesn't actually clear the circular buffer memory - it just resets the start & end of data pointers, so writing and reading to/from it should still give the correct result.

Martin

Ferla
Flowcode v5 User
Posts: 126
Joined: Sun Jan 06, 2013 8:58 pm
Location: Italy
Been thanked: 19 times
Contact:

Re: Optimize rx bytes

Post by Ferla »

Hi Martin
Sorry for the delay, maybe I found the mistake.
It was a delay of 100ms in the macro. I do not know yet why I inserted it maybe a mistake or maybe when I was simulating in FC.
However, now it works well, I pushed the Uart transmission up to 80ms and did not give any problems. Speed that I never achieved was just a trial.
Now the battlefield test remains.
Thanks for the interest, really a serious professional :wink:
A big Hello
Ferla
Attachments
Error.png
(214.44 KiB) Downloaded 2256 times

Post Reply