Update to Arduino Serial Input Basics Example #5

Robin's demo is just that, a demo (guide) about receiving. I'm sure that there are a few topics where timeouts for his recvWithStartEndMarkers() were demonstrated; it's a useful addition where there is a risk that serial communication breaks.

The rest of his code is up to the user; you have demonstrated that in the parseData() function to check but it's not necessary for the receiving.

FYI, I've demonstrated timeouts in Serial has no terminator, so use a word for one? - #6 by sterretje (last code block) for a scenario where there were no markers.

For computer-to-computer communication that is not really applicable. It's only when the user has to type commands that it is a valid argument; from a coding perspective the use of enums representing numeric values for commands is just as readable in my opinion.

Note:
Personally I consider the copying of the received characters to a temporary buffer useless and a waste of memory. There is only a need for that if there is a need to not to destroy the content of the receivedChars buffer (which I think is highly unlikely).

Hi, thank you, this was genuinely helpful. I will check into your link and I appreciate it.

I am a beginner, and though I've spent a couple years coding (and an embarrassing amount of time), most of that has been with getting LCD screen graphics working just so, and working out other aspects that haven't required anything like this.

I will check into the use of ENUMs. I think that may be the way to go, to keep the code readable by me, yet still compact.

By the way, honest question for anyone, is the Arduino IDE just considered laughable by "real" coders? I have access to Visual Studio if need be, but the thought of redoing a huge project in another IDE and possibly a variant or different coding language is scary to me.

Hi, I would recommend PlatformIO/VScode, I use Arduino IDE just for simple examples and testing short sketches.

Hi, thank you. I've heard of it before. I'll look into it.

I recently just upgraded from Arduino IDE 1.58x to 2.x, and it's a huge difference alone.

Thanks again.

Mike

After reading through some of yours and others' posts here, I realize I have quite a huge lot left to learn here.

Thank you all again.

Mike

I don't know and I don't care, it is a tool to do a job. That job is mainly to help people new to coding to learn, I think the Arduino IDE does a really good job at that task. I consider myself to be a reasonably good hobby programmer in C with a bit of C++. As well as the Arduino IDE I also use MPLABX, which is Microchip's IDE for PIC (and also AT now Microchip own Atmel). MPLABX is not a beginner's IDE, there are far too many features a beginner does not need, but a beginner would not know where to start with it, which features are required and which can be ignored. With the Arduino IDE they made it easy to get started and get some working code quickly. It does the job of helping beginners really well in my opinion, if you get to a level of expertise where you wish it had features it doesn't have then you can consider something else. I doubt a bricklayer would consider the Lego bricks his son plays with to be 'laughable' just because they are not real bricks, they are a different tool for a different job.

I'm just getting used to the concept of Strings are evil. Thanks for pointing this out.

From another thread there is a SafeString lib that I'm looking into...at the moment I'm afraid getting proficient in c-strings and C++ version of these guys feels a bit overwhelming...

Thanks for this.

Thank you. I have used a ton of arrays in my code, but not with strings. Yes, they are very cool.

I appreciate it.

The String class may be used safely if one knows what they are doing and don't mind the memeory use. But new users do not learn the safe ways and hence we get questions about bugs that crop up hours, days or weeks later when the heap crashes

Null terminated character arrays are safer snd use lesss memory, but still can suffer from buffer overflow.

Some care must be taken either way.

Even though i know how to use them i very seldom use Strings.

I have been a microcontroller hobbyist for over 50 years (mostly 8051 assy) and Arduino hobbyist for around10 years. The Arduino IDE works fine for me.

Hi groundFungus,

I really appreciate your perspective. Thank you.

I am now revisiting the whole subject. I think because the Teensy 4.0 MCU has so much memory, I haven't run into any memory issues with Strings, but maybe I've just been lucky.

I can see for what I'm doing next, making an app to interface with the MCU using serial coms, I need to step up my game.

Thank you kindly,

Mike

PS I just read your evil strings article link; excellent! Ta for that!

In the course of getting ready for Hallowe'en every year, what I don't have much of is anything in the way of documentation. They are arcade type games, so not something you can play without the installation.
I have a 5 foot tall, converted electric wheelchair type robot based off the Sentry Bot from Fallout 3/4 video games. Its locomotion is straight up RC (Spektrum aircraft type).
It uses an Xbox Kinect camera to detect and track trick or treaters' body positions (threatening or non) and/or hand gestures. If threatening, get warned. Keep threatening, get blasted with Nerf Rival balls (the arms). If non threatening, pass but gain no access to the soldier's memories locked within its imprisoned consciousness, which players must unlock by manipulating a series of faint, rotating cubes in the virtual space between it and the player. I thought that with the popularity of the show Stranger Things, it would be fun if that element was hidden in an interpretation of "The Upside Down" from the show, and one of the ways in is to sort of "force push" your way in, the way protagonist Elle battles various evil in the TV show.
The end goal is a spoken statement that will give the player two things: the code to the Fallout sytle terminal at the back of the laser maze beyond the robot and in my garage, and the location of the Museum of Witchcraft (the end stages of a live action "video game" that trick or treaters didn't even know they were a part of). Bot telemetry and blaster control through Arduino. Chars are exchanged between the Arduino and a laptop (Kinect and running Processing, I use a wireless HDMI tx/rx to broadcast the laptop screen to a nearby projector. displayed on an inflatable screen.
The other Processing game is the instructions, music, scoreboard for the laser maze in the garage. It's a huge fan fave.
The GI Joe app uses RFID attached to figure stands (every figure from '82 - '94, 640 or so iirc, vehicles too, another 300 ish). Scan a Joe, their file card, courtesy of 3DJoes.com (used with permission), comes on screen. Interact with elements on the screen and links to relevant comic books over the years come up and also stats are loaded into a buffer to have them perform simulated missions against the enemy, Cobra (and vice versa). Sort of a D and D type simulation where the user gets a pass/fail for some set of mission parameters. That part is as yet unfinished, but I have stopped working on this project due to the abysmal feedback from the two people I made full working samples for: the owner and archivist of 3DJoes.com and a superfan, recently retired US Army combat arms veteran. As such, two final prototypes exist and I gave them both away. I have parts to make more but programming in that many RFIDs is tedious and the disheartening response sort of turned me off from the GI Joe collecting community. if you think there's gatekeeping in the Arduino hobby, boy howdy let me tell you some stories... :joy: :rofl:
Anyway, here's a link to a Sentry Bot video, halfway through it cuts to a clip of the laser maze setup, readying the night before Hallowe'en iirc. There are some others on my YouTube page. There were lots of code revisions after these were taken but you can get an idea.

Of note, every game in the links relied entirely on @Robin2 's Serial comms methods.

The Sentry Bot game is called Threat Matrix:
Threat Matrix and Laser Maze setup
Upside Down memory unlocking testing pre installation
GI Joe dossier
You have any clips of your game?

OMGoodness! Honestly I couldn't get the full picture of what you created, only that it is exceptionally cool and exciting! I don't want to clutter up this thread, but maybe you can PM me and tell me more?

Whatever you do, don't give up your dreams cos of a couple naysayers. They probably just didn't get it. Visionaries gotta vision.

Mike

Of general interest in this thread:

Taming Arduino Strings

Thanks for sharing. The best explanation of the topic I've ever read, easy to follow and to the point.

well’ not sure I’m getting what you are saying
If > is the end marker and the code waits for it, you’ll will have in the buffer <hi<hi, 23<hi, 23>
And only then will you be notified about the new entry
So it’s at parsing stage that you’ll get rid of the wrong input based on your grammar

That was how the original sketch worked.

In my testing this update only acknowledges complete entries, and generates a timeout or a parsing error if incomplete.

That’s what I need to see and use - completed messages or an error.

Try running it?

I’m reading from my iPhone, can’t try - but OK if you added stuff then you are departing from the goal of the tutorial and moving into more tailored code (which is OK)

Timeout can be a double edge sword.. if I type <hi,123 and then wait long enough for time out and then send the > you’ll have ignored a well formed input.

Yes, the goal I stated was clear - to provide clean output only if correct syntax entered. It is tailored to this goal.

Timeout can be lengthened, or code removed. But if it takes more than 500ms then it’s safe to say there’s a com problem. And I don’t want half-formed input getting through.

Thanks for the message.