I am using Arduino Mega with TPIC6B595 the leds are working perfectly but I have connected the pin 9 (OE and this with ground) to pin 12 Arduino to get less brightness but the led bright full.
I am using Monitor Serial to send a number.
can you tell me what I am doing wrong please?
many thanks.
long i=0;
//Pin to clear the register
const int clearPin = 7;
//Pin connected to latch pin (RCK) of TPIC6B595
const int latchPin = 8;
//Pin connected to clock pin (SRCK) of TPIC6B595
const int clockPin = 6;
////Pin connected to Data in (SER IN) of TPIC6B595
const int dataPin = 9;
const int notG = 12; //not G PWM DIMMER
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(clearPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(notG, OUTPUT);
Serial.begin(9600);
Serial.setTimeout(10);
Serial.println("*");
// Always start by setting SRCLR high
digitalWrite( clearPin, HIGH);
// delay a little and then set
delay(100);
}
void loop() {
while (Serial.available()==0){}
i=Serial.parseInt();
Serial.println(i);
analogWrite(notG, 10);
// write to the shift register with the correct bit set high:
registerWrite(i, HIGH);
delay( 1000 );
}
// This method sends bits to the shift register:
void registerWrite(int whichPin, int whichState) {
Serial.println(whichPin);
// the bits you want to send
byte bitsToSend = 0;
// write number as bits
bitWrite(bitsToSend, whichPin, whichState);
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
Serial.println(bitsToSend);
Serial.println("_");
// shift the bits out
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}
Well it is not the best way of doing a serial input, as soon as one byte arrives in the buffer you immediately try and convert the single byte into an integer. Leaving the next byte of the one input.
Read up on how to handle serial inputs.
Also try a analogue write of a much bigger number like 128, for a start.
That is not a schematic it is a physical layout diagram, what is known here as Fritzing crap.
However I can see you have the LEDs wired wrong. Each LED should have its own resistor not one resistor for all LEDs. You also don't seem to have any decoupling capacitors. Also it seems you have shorted pin 12 to ground, so how can it ever go high?
We also need to see how you have wired it, so a photograph will tell us if the schematic ( when you post it ) matches what you have done.
I only need one resistor because I am using one led at a time, no two or more light on at the same time.
OK but information that should have been in the first post.
Also if you take just a tiny bit more care with placing the wires you can obscure where all of them go not just most of them. Think about it could you follow the wiring from that photograph? The Fitzing crap shows you short out the resistor you think you have in the LEDs.
About the capacitor I didn't know that I need it. Where to put and what value?
0.1uF ceramic between the power pin and ground of the chip.
and about shorted pin 12 to Ground is beacuse If I connect only the OE pin no light comes on, but when I connect to ground it works.
So you ruin any chance of it working and perhaps damage the Arduino pin by putting a short circuit on it.
Try this:-
Remove the wire to pin 12
Output an LED so it is lit.
Remove the short, to the OE, the light should go out, if not connect it to 5V. So basically the LED is lit when the OE is connected to ground and not lit when it is open or connected to 5V.
Then remove the wire from the OE and connect up the wire to in 12, make sure you set the analogWrite to 128. If nothing happens then you have blown your Arduino pin. Try another PWM capable pin, remember to change your code accordingly.
I have put all anodes together and one resistor for all them. As I said before, I only lit one led at a time.
Is this not the correct way to do it?
If not, please can you tell me how to connect them?
thanks
This is very silly. It almost suggests that you are exceeding your current skill set and need to do some more basic circuits.
You put the resistor between the bottom red line and one of the vertical lines above it. Then you put the link to the top red line to one of the five holes vertical line you put the resistor to.
Well it is not the best way of doing a serial input, as soon as one byte arrives in the buffer you immediately try and convert the single byte into an integer. Leaving the next byte of the one input.
I need to send an integer with two digits for example:35 and then lit the corresponding led.
If this is not the best way to do it, please, can you tell me how?
Another question, I have to use 4 more TPIC6B595 do I have to put one capacitor in every TPIC6B595?