Pages: [1]   Go Down
Author Topic: Serial to Parallel Shifting-Out with a 74HC595 - Example issue  (Read 588 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I've tried to implement the program found at this page http://arduino.cc/en/Tutorial/ShftOut12.
It makes an example on how to use a shift register (circuit connections are here http://www.arduino.cc/en/Tutorial/ShiftOut).

In such an example, when I send my bit/pin selection via the serial line through the IDE Monitor interface, the micro runs the loop twice (thus it processes the "shifOut" command two times) even if I send my input just once.
The first time it indeed processes exactly my bit selection (a number from 0 to 7), the second time it processes a "carriage return" character.

This implies that, on the second time, the variable "pinToSet" becomes -35 (since the ASCII value for the carriage return is "13"). Finally, at the end of the second shiftOut, only the least significant bit is set HIGH.

Practically: whatever LED you choose to light up, you get it flickering only, but then the program freezes the register value upon the second loop closure and you always get your first LED permanently turned on (not the once you chose).

In order to fix the issue, I've therefore added just an additional "if" after the one already present in the program, so that the loop becomes:

Code:
void loop() {
  if (Serial.available() > 0) { 
    int bitToSet = Serial.read() - 48;                                       
    if (bitToSet < 0) {
      bitToSet = prevBitToSet;
    }
    else {
       prevBitToSet = bitToSet;
    } 
  }
    registerWrite(bitToSet, HIGH);
}

So when the program processes the "carriage return" which apparently is always generated, I restore the value I chose with my selection.
Let me know if you also experienced such a behavior or if the additonal "carriage return" character is added by default by the IDE Serial Monitor, so it must indeed be filtered out.

Thanks for your feedback!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So when the program processes the "carriage return" which apparently is always generated, I restore the value I chose with my selection.
Always generated by what? If you are using the Serial Monitor application to send the data, the carriage return (and line feed) is always generated only if you choose that option. If you don't want that, and can't figure out how to ignore it (trivial), don't pick that option.
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 109
Posts: 4088
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What have you got the serial monitor line ending set to ?
No line ending ?
Newline ?
Carriage return ?
Both NL & CR ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/serial
Logged

Pages: [1]   Go Up
Jump to: