Displaying data in Serial Monitor

Hello all,

This is sort of a sub-topic to a larger task I'm working on so I'll keep it as simple and relevant as possible.

The goal is to read the 0's/1's from 16 data bits (off a ribbon cable), and eventually put it into a spreadsheet for analysis. My current approach is to run the code, and capture it via Serial Monitor, to copy and paste it into Excel. (I'm using the Uno)

Here's my code:

void setup()          
{
  Serial.begin(9600);     
                          
  pinMode(0, INPUT); // digital 
  pinMode(1, INPUT); // digital 
  pinMode(2, INPUT); // digital 
  pinMode(3, INPUT); // digital 
  pinMode(4, INPUT); // digital 
  pinMode(5, INPUT); // digital 
  pinMode(6, INPUT); // digital 
  pinMode(7, INPUT); // digital 
  pinMode(8, INPUT); // digital  
  pinMode(9, INPUT); // digital 
  pinMode(10, INPUT); // digital 
  pinMode(11, INPUT); // digital 
  pinMode(12, INPUT); // digital 
  pinMode(13, INPUT); // digital 
  pinMode(14, INPUT); // A0 
  pinMode(15, INPUT); // A1 

}

void loop()                      
{

    Serial.print(digitalRead(0)); // DB00
    Serial.print(",");
    Serial.print(digitalRead(1)); // DB01
    Serial.print(",");
    Serial.print(digitalRead(2)); // DB02
    Serial.print(",");
    Serial.print(digitalRead(3)); // DB03
    Serial.print(",");
    Serial.print(digitalRead(4)); // DB04
    Serial.print(",");
    Serial.print(digitalRead(5)); // DB05
    Serial.print(",");
    Serial.print(digitalRead(6)); // DB06
    Serial.print(",");
    Serial.print(digitalRead(7)); // DB07
    Serial.print(",");
    Serial.print(digitalRead(8)); // DB08
    Serial.print(",");
    Serial.print(digitalRead(9)); // DB09
    Serial.print(",");
    Serial.print(digitalRead(10)); // DB10
    Serial.print(",");
    Serial.print(digitalRead(11)); // DB11
    Serial.print(",");
    Serial.print(digitalRead(12)); // DB12
    Serial.print(",");
    Serial.print(digitalRead(13)); // DB13
    Serial.print(",");
    Serial.print(digitalRead(14)); // DB14  aka A0
    Serial.print(",");
    Serial.println(digitalRead(15)); // DB15  aka A1

  }

The results in the Serial Monitor are of the following. Also, note that it continuously stream the 0's/1's, but since I can't exactly attach a video, here's a copy/paste of what it looks like:

1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0

And it keeps on going to continue collecting.

Questions: 1) Why are there 1's in pin 0 and pin 13? There is nothing physically attached to those pins so shouldn't they also be 0? I also tried connecting a wire from GND to pin 0 and/or 13, and they would display 0's, but once I remove the wire, it goes back to 1's. What's happening?

2) In tinkering around, I put a wire between 5v and random pins (0-15). With the exception of those pins described in the previous question, I confirmed that I can trigger 1's to display in the pins of those the wire is connected to. However, upon removing the wire, the 1's continue displaying in the Serial Monitor for about six seconds, before returning to 0's. Why and how do I get rid of this delay?

3) Also, as it streams the data in Serial Monitor, I have noticed that some of the 0's will sometimes randomly become 1's momentarily, then return back to 0's. Nothing is attached to any of the pins. What's causing this, is it picking up some sort of "noise"?

Thanks in advance for your help!!! :)

1) Why are there 1's in pin 0 and pin 13?

Have you looked at the schematics?

However, upon removing the wire, the 1's continue displaying in the Serial Monitor for about six seconds, before returning to 0's. Why

Floating input.

how do I get rid of this delay?

Add pullups or pull-downs

3) Also, as it streams the data in Serial Monitor, I have noticed that some of the 0's will sometimes randomly become 1's momentarily, then return back to 0's

See previous answer

Why is your code so big?

Pins 0 and 1 are used for Serial communication with the PC - don't use them for inputs from your ribbon cable.

Pin 13 is connected to the on-board LED and it is probably wise not to use that.

All of the analog pins can be used as regular digital pins if you need to.

...R

user for loops for your code. This makes an array to hold the 13 “1s and 0s” and reads digitalpins 0-12 included (13 values in total) and places them in the corresponding array position.

int array_for_pins[13];

for (int pin = 0; pin < 13; pin++){


array_for_pins[pin]=digitalRead(pin);

}

Also, use pins 3 to 13 and you can use the analog pins (digital read does work with them I believe).

Pins 0 and 1 and used for other things on the arduino such as Tx/Rx with a PC etc.

waynewayne: capture it via Serial Monitor, to copy and paste it into Excel.

You will have better luck using a proper terminal programme like RealTerm. If you use an older version of Excel, you can feed the data direct to it using the PLX-DAQ macro. This macro essentially makes Excel into a terminal.

AWOL: Have you looked at the schematics? Floating input. Add pullups or pull-downs See previous answer

Why is your code so big?

Thanks all for the responses!

AWOL, I assume that when you say look at the schematics, you're suggesting me to see that pin 0 and pin 1 is used for TX and RX? And to see that pin 13 is used for the LED? Coupled with info from other responses, does this imply that I should never be using pin 0 and 1 and 13? I thought maybe I could bypass their primary/designated purposes just to utilize all the pins (I need 16 pins for data bits, and 3 for signal/control lines).

I added pull-downs to each input and was able to resolve the issue I had on pin 13, does that the on-board LED at pin 13 doesn't restrict pin 13's use for other purposes?

And I guess my code is pretty big because I was trying to separate the 0/1's with commas so I can copy/paste it into Excel... How can I reduce the code size?

If I cannot use pin 0, 1, and/or 13, then the Uno won't have enough I/O (both analog and digital) lines for my interface. Is this right? If so, does this mean I need to use a different arduino? Any recommendations?

Robin2: Pins 0 and 1 are used for Serial communication with the PC - don't use them for inputs from your ribbon cable.

Pin 13 is connected to the on-board LED and it is probably wise not to use that.

All of the analog pins can be used as regular digital pins if you need to.

...R

Robin2,

I tried using pin 13 (with pull-downs) and it seems like it does work. Am I overlooking something, and should I just (out of caution) just avoid using pin 13?

So with the analog pins (6 analogs) and the digital pins (14 digitals, then minus pin 0,1, and 13), the Uno will have 17 I/O pins. I actually need 19 (16 data bits, and 3 signal/control lines), so does that mean the Uno is not a viable option for me? If so, does that mean I need a different arduino? Would other boards be similar such that replicating the code over is similar to setting up the code on the Uno (pins, etc)? And also, if you do recommend, which board would be best?

Thanks!

Johnny010:
user for loops for your code. This makes an array to hold the 13 “1s and 0s” and reads digitalpins 0-12 included (13 values in total) and places them in the corresponding array position.

int array_for_pins[13];

for (int pin = 0; pin < 13; pin++){

array_for_pins[pin]=digitalRead(pin);

}

Johnny010,

In my other reply to Robin2, I did the math and it seems like the Uno does not have sufficient pins for me. Would your suggestion of for loops and arrays resolve this issue?

Also, help me understand your code suggestion. Is the logic saying that you’re defining an array for pin 0-12, and reading each pin starting at pin 0 (as long as it’s under pin 13), then increasing it in increments? Does the ++ mean an increment of 1 or is it a just a placeholder to re-write “pin+1”?

Thanks!

Nick_Pyner: You will have better luck using a proper terminal programme like RealTerm. If you use an older version of Excel, you can feed the data direct to it using the PLX-DAQ macro. This macro essentially makes Excel into a terminal.

Nick_Pyner,

Thanks for the suggestions! PLX-DAQ does seem interesting, just downloaded it and will tinker with it. Will also look into RealTerm as well. I've never used these tools before, so I may have a few questions for you on it :)

Thanks!

Also, in protecting the circuit when doing a pull-down resistor, I'm using a 10k ohm resistor as the pull-down and then a 100 ohm resistor to protect it from shorts in case I accidentally set input as output Source: http://www.ladyada.net/learn/arduino/lesson5.html

Side question: I've added 10k ohm resistors to each pin, but I only have several 100 ohm resistors with me. The next closest resistors I have available are 120 ohm and 82 ohm resistors. Can I use some of the 120 ohm or 82 ohm resistors in lieu of the 100 ohm? Is there a specific reason why it is 100 ohm?

You can get external chips to expand the number of I/O pins available to an Uno (I forget the name right now) or you could use a Mega. Using the Mega would be much simpler - but also more expensive.

...R

Would using the Mega be similar to the Uno? Similar syntax, commands, logic flow, etc?

Also, why are there so many varying Megas available? Here's the original arduino brand version: http://www.amazon.com/Arduino-Mega-2560-MEGA-R3/dp/B006H0DWZW/ref=sr_1_1?s=pc&ie=UTF8&qid=1441471883&sr=1-1&keywords=arduino+mega

Looks like the others are "clones" http://www.amazon.com/Ximico-Arduino-Cable-Atmega2560-16au-Compatible/dp/B00KG3SBE8/ref=cm_cr_pr_product_top?ie=UTF8

http://www.amazon.com/Arduino-Compatible-Atmega2560-Mega2560-Board/dp/B00JTBMD7E/ref=cm_cr_pr_product_top?ie=UTF8

http://www.amazon.com/Mega2560-ATmega2560-16AU-ATMEGA16U2-MEGA2560-Duemilanove/dp/B00OH21CRM/ref=sr_1_5?s=pc&ie=UTF8&qid=1441471883&sr=1-5&keywords=arduino+mega

http://www.amazon.com/Arduino-Atmega2560-16au-Compatible-Beginners-Download/dp/B00KJGV5WC/ref=sr_1_7?s=pc&ie=UTF8&qid=1441471883&sr=1-7&keywords=arduino+mega

Should I go with an arduino brand or a "clone"? The clones are definitely cheaper but if they have out-of-the-box problems, I'm willing to spend the money on the arduino brand. What do you suggest?

I've used the Sainsmart Mega numerous times and have always had good luck with them using the Arduino IDE. See:

http://www.ebay.com/itm/SainSmart-Mega2560-R3-Board-ATmega2560-16AU-ATMEGA16U2-USB-Cable-for-Arduino-/271187169712?hash=item3f2403d1b0

While not the cheapest clone, at less than $13 including shipping, it's a pretty good deal and it would solve your pin problem. (I have no financial interest in SainSmart.)

Thanks econjack, it does look pretty good. But it's shipping in from China? If you ordered from this seller, how long did shipping take? It looks like delivery is between sept 15 and 29

I found the same product on amazon which I can borrow a friend's prime account, and have it delivered in 2 days: http://www.amazon.com/SainSmart-Mega2560-ATmega2560-16AU-ATMEGA16U2-Duemilanove/dp/B00CF2REXC/ref=sr_1_1?ie=UTF8&qid=1441474084&sr=8-1&keywords=sainsmart+arduino+mega

It's a bit more pricier than what's listed on ebay. Is it still worth it at amazon's price ($22.72)?

Is it still worth it at amazon's price ($22.72)?

Only you can answer that question. It's a good board regardless of where you get it from.

I only have a genuine Arduino Mega.

The advantage of starting with a genuine board is that if something does not work you can be confident it is your fault rather then the fault of the board.

Later if you buy a clone you can always compare it with the original if there are problems.

...R

I ordered the arduino brand! Should arrive in two days via amazon. Thanks econjack and Robin2! I figure I can proceed to the clones later when I feel more confident, and will probably buy the SainSmart board then!

ALSO, any suggestions on my previous questions about the 100 ohm resistors in the pull-down configuration? Does it have to be 100 ohm? I ran out of 100 ohm resistors, can I use 120 ohm or 82 ohm resistors (what I have available)?

Thanks!

A 120 ohm resistor in parallel with an 82 ohm resistor would be equal to a 101 ohm resistor. That is certainly close enough to 100.

PaulS: A 120 ohm resistor in parallel with an 82 ohm resistor would be equal to a 101 ohm resistor. That is certainly close enough to 100.

120*82/(120+82) = 48.8 ohms