Whether you are using serial communication as an input or an output, you
need to use the
begin()
method to start your serial port. The baud rate
can vary, but 9600 is the standard for most applications.
Serial.parseInt();
There are a number of ways to read and parse data coming in from the
serial port. The simplest way is to format your data coming in as a Comma-
Separated Value (CSV) string. In this format the
parseInt()
method
captures the data as it comes in. Once the there is a non alpha-numeric
character (a character that is not a letter or a number)
parseInt()
will stop
capturing the value as an integer. As an example if we were to send the
string
123,456,789
through
parseInt()
it would return the value of 123
because it would stop capturing at the comma (,).
In this experiment we use the
parseInt()
method three times, one right
after the other, to capture the three comma-separated RGB values and
place them in the three color variables.
What You Should See
You should see nothing at first when your upload is complete. Open up the
Serial Monitor (The magnifying glass icon in the upper right-hand corner of
the Arduino IDE). You should see the text “Please enter your RGB in CSV
format(Example: 255,100,0)” print out in the serial monitor.
Enter an RGB value, (we are using
255,100,0
as an example) in the text
entry area as shown below and click ‘Send’. Once you click the send button
your RGB should turn a purple color. Congrats! You just sent data to your
RedBoard from your computer!
Troubleshooting
LED Remains Dark or Shows Incorrect Color
With the four pins of the LED so close together, it’s sometimes easy to
misplace one. Double check each pin is where it should be.
You are Sending Data but Nothing Happens
Make sure you are sending your data as integers between 0 and 255 in a
comma-separated format.
Resources and Going Further
There are tons of sensors and shields that you can hook up to your Arduino
101 board to help take your projects to the next level. Here is some further
reading that may help you along in learning more about the world of
electronics.
For more info on Arduino, check out these tutorials:
• Arduino Resources and Curriculum
• Arduino Comparison Guide
• Arduino Shields
Page 62 of 63