Hi,
I am experimenting with shift registers and LEDs, basically turning on and off LEDs one by one (scrolling) as a first step.
I uploaded the following code to my Arduino. It worked fine (i.e. turn on and of 8 LEDs connected to the output of a shift register) however when I recycle power to the Arduino, the circuit stops working. To get it work I need to upload the code again and keep it like that, any recycling of power will require uploading the code again.
I tried few time getting help about this topic because I had this issue with other projects in the past, but so far no one provided any helpful suggestion. I hope this time someone will help. Thank you
here the code:
//Pin Definitions
// 7HC595N has three pins
int data = 2; // where we send the bits to control outputs
int clock = 3; // keeps the data in sync
int latch = 4; // tells the shift register when to activate the output sequence
void setup()
{
// set the three control pins to output
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
Serial.begin(9600); // so we can send debug messages to serial monitor
}
void loop(){
outputBytes(); // our basic output which writes 8-bits to show how a shift register works.
//outputIntegers(); // sends an integer value as data instead of bytes, effectively counting in binary.
}
void outputIntegers(){
for (int i=0;i<256;i++){
digitalWrite(latch, LOW);
Serial.println(i); // Debug, sending output to the serial monitor
shiftOut(data, clock, MSBFIRST, i);
digitalWrite(latch, HIGH);
delay(100);
}
}
void outputBytes(){
/* Bytes, or 8-bits, are represented by a B followed by 8 0 or 1s.
In this instance, consider this to be like an array that we'll use to control
the 8 LEDs. Here I've started the byte value as 00000001
*/
byte dataValues = B00000001; // change this to adjust the starting pattern
/* In the for loop, we begin by pulling the latch low,
using the shiftOut Arduino function to talk to the shift register,
sending it our byte of dataValues representing the state of the LEDs
then pull the latch high to lock those into place.
Finally, we shift the bits one place to the left, meaning the next iteration
will turn on the next LED in the series.
To see the exact binary value being sent, check the serial monitor.
*/
for (int i=0;i<8;i++){
digitalWrite(latch, LOW);
Serial.println(dataValues, BIN); // Debug, sending output to the serial monitor
shiftOut(data, clock, MSBFIRST, dataValues);
digitalWrite(latch, HIGH);
dataValues = dataValues << 1; // Shift the bits one place to the left - change to >> to adjust direction
delay(30);
}
}
Thank you
I am using this: ATMEGA328P-PU
I don't know if it's a standalone microprocessor or not, I don't know how to check for that. But I know it works for other program such as a blinking LED program. It works all the time even after recycling power. Also I made a small alarm system using a range finder, LEDs and a buzzer and no issues, but I had problem with a program that I used to control a micro pump and another one involving a keypad. So I don't know if it's the code or using the wrong microprocessor but if that's the case why it worked with some programs and not others.
To upload I use the arduino UNO. I had the microprocessor plugged in the Arduino UNO and I used the USB and my laptop to upload the software to it using the Arduino evironment.
I hope I was clear in explaining the issue and thank you for considering my post. Thanks a lot, if you help me with this you will save me a lot of headaches.
ferkheusa:
I don't know if it's a standalone microprocessor or not,
Well, you used "standalone" as the title for your Thread so I assumed you knew! (Silly me :))
Standalone just means that the device is working (perhaps on a breadboard) while not inserted in the Uno.
If you have a standalone circuit it would be very useful if you could post its wiring diagram. A photo of a clear pencil sketch will be fine.
On the other hand if your code is only being used while the 328 is plugged into the Uno board let us know. And it would probably help your search for advice if you renamed the title in your original post to something more meaningful.
Yes! My code is only being used while the 328 is plugged into the Uno board.
What would be a meaningful title and where should I post it to get a good answer to this.
I've built small projects where I used the 328 on a breadboard but, again, I noticed that with some programs it works fine in the UNO or on the breadboard but with some programs it doesn't when you recycle power.
Thanks
As far as the title goes it seems like your problem could be described as "Sketch lost when power disconnected". You can change the title by editing your first post. I suggest you then ask the moderator to transfer the Thread to the Project Guidance section.
As far as the problem goes you need to provide a much more detailed explanation of what you are doing. It seems like you are not using the 328 that came with your Arduino?
Why not? (an explanation - not a justification)
What bootloader is on the new 328?
How did it get there?
And there are probably many more relevant questions.
I find that you are trying to convey too much information in too few words which makes it difficult for me to follow.
I am, basically, trying to implement the first example (using one shift register). The example can be seen here:
The purpose is to use it for a scroll sign but before I get there. I wanted to get the basics first.
The final project will be like this: I will use a range finder or another mention sensor and when triggered it will cause a message to scroll.
for now I just wanted to be able to get that first example working without loosing the sketch when I recycle power.
I got the 328s a while ago. I remember the seller told me they have a boot-loader installed in them and should work just like the one you buy with the Arduino.
You raised a good question. I don't know what a bootloader does and are there different bootloaders?
Thank you very much for your help.
If you want to sort out this problem it can only be done one step at a time.
First step ...
Have you got the original 328 that came with the Arduino?
If you insert that in the Arduino can you upload code to it?
And does the code stay on the Arduino when you disconnect power?
First, thank you very much for getting back to me.
I performed the test you suggested. here is the outcome:
1- I don't think I still have the original ATMEGA328 that came with the Arduino. I bought the arduino 3 years ago and later I bought 10 ATMEGA328Ps to use in projects that I may think about; then I stopped for a while and now I wanted to go back to Arduino, so I am not sure if I still have the original or not but I know that I used these 328 before in other circuits and worked fine. I guess I need to go back and try them again.
2- As I mentioned in a previous message I use the Arduino IDE to upload the code to the ATMEGA328P. When the upload is completed I get a message on the IDE that the upload is completed, if not it spits some errors.
3-When I uploaded your code I saw that LED near pin 13 on the Arduino blinking at a rate of 5HZ (approx.) I also opened the serial monitor to see the message and got "Hello from Arduino"
4- I pressed the reset button that is near the USB plug on the Arduino to see what will happen and didn't notice any changes except that every time you hit reset the serial monitor prints the message, the LED blinking rate was the same.
5- However when I unplug and plug the USB (Recycle power) the sketch got lost. I had to upload it to get it back to normal.
That's what I observed.
Now you made me think that maybe these 328s is the problem. I hope so.
Can you suggest a place where I can get a good 328 ; also could tell me what to look for when you buy these little devices. Thank you again. Thank you.
The blinking and the printing that you describe are exactly what should happen.
I think the simplest thing for you would be to buy a new 328 from a reputable supplier with the bootloader already installed (or just buy a new Uno if you can afford it - it can be very useful to have two of them). You don't say what part of the world you are in so it is hard to recommend a source of supply. In the UK I would try RapidOnline or Proto-Pic. Other possibilities are Sparkfun and Pololu.
When you have an Uno that is working normally it will be possible to upload the bootloader to the other 328s.