Go Down

Topic: SerialInteraction (Read 107 times) previous topic - next topic


Jan 15, 2017, 11:18 pm Last Edit: Jan 16, 2017, 03:10 pm by Terryjmyers Reason: Attached file instead of a link to Github
Terry Myers <TerryJMyers@gmail.com> https://github.com/terryjmyers
Template to interact over Serial monitor with Arduino

The following is a simple sketch that you can incorporate into your sketches in order to interact with your project programmatically.  It includes a simple serial menu system that greets the user with prompts.  The ideas presented here can eliminate the need rotary encoders, potentiometers, push buttons, etc, if the end user is willing to simply connect to the project to interact with it over serial.

Some ideas:
1. During prototyping, setup commands to set and reset output pins or directly set variables
2. During running projects, setup commands to save configuration data to the EEPROM
3. Update the RTC time by sending the time in Comma separated values (CSV) over the serial interface.
4. Save on wiring up a potentiometer by simply sending a command over serial to mimic the position


Jan 15, 2017, 11:45 pm Last Edit: Jan 15, 2017, 11:46 pm by Robin2
Make life easy for Forum readers and attach your code to your post.

Have you seen Serial Input Basics - simple reliable ways to receive data. There is also a parse example.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

Two or three hours spent thinking and reading documentation solves most programming problems.


Jan 16, 2017, 12:14 am Last Edit: Jan 16, 2017, 12:48 am by Terryjmyers
Thanks, this tutorial was pretty helpful.

My code was too large for a post

To prevent memory corruption one should reserve the string space.  That is why this is added:
Code: [Select]
//Set serial read buffer size to reserve the space to concatnate all bytes recieved over serial

Also my code presents a framework for useful interaction simply by telling the user what commands are acceptable and what they will do, which can be incorporated into an actual product, or to make supporting your finished projects easier, such as:



My code was too large for a post
You can add your .ino file as an attachment

Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131