Is current going in reverse through the shift register?

Dacha011:
@PaulRB - Thanks for sharing you view on I1 & I2 with me !

@MarkT - "Almost all logic chips require all logic inputs and outputs to be within the range GND-0.3V and Vcc+0.3V at all times, powered up or not." - wooow, info like this are worth pure gold for a beginner like me. It saved me not only many hours of debugging and struggling to find out the problem, but probably it also saved many IC from being fried ! Thanks MarkT !

While you were told what is wrong, there hasn't been an explanation for why doing this is bad, so I'll give it my best shot here.

I've attached a diagram of how the output pins work for a certain chip. While all chips will have different logic attached to them, the key feature to pay attention to here are the two diodes next to the I/O pin marker. basically all digital chips you use will have a pair of these diodes on every pin. You may already know that diodes have a relatively constant amount of voltage drop no matter the current flowing through them. The pair of diodes on the pin provide a path for static to discharge into the chip without creating an obscene amount of voltage in the process.

The diodes are connected directly to the chip's power rails so that static discharge through them is dumped straight out of the chip instead of through the electronics. However, if the chips power is disconnected and you apply voltage to one of the other pins, the power can travel up the VDD diode and give power to the entire rest of the chip. If you have GND connected to another pin, the current from the circuitry can travel up the VSS diode and get out of the chip. This "phantom powers" the chip, and can be enough to allow partial operation.

There's some more discussion of it here on this Stack Exchange thread: Will cutting power to a CMOS chip effectively remove it from the circuit? - Electrical Engineering Stack Exchange

Dacha011:
Since I'm certain that I will have more questions regarding this project, is there a part of the forum in which I can open a topic and post questions re my project (project guidance) ? I don't want to go off-topic here.

Since so much information - including your pictures - has already been given here, it might be best to simply continue this thread and change the topic in the first post to the new concern.

Paul__B:
Since so much information - including your pictures - has already been given here, it might be best to simply continue this thread and change the topic in the first post to the new concern.

No. Don't do this.

@Jiggy-Ninja - Thanks for the clarification. I must admit that I have only partially understood the concept. Anyway - I will save your explanation, maybe for a few months I will have a deeper understanding. All in all - if there is no VCC, and the I/O pin is attached to a certain voltage, the current can go through the chip (not desired) until it gets to its destination (like GND).

@Paul_B - Roger that !

:wink:

Hi everybody! The problem with the shift register is resolved, everything works fine now. Take a look at the progress:

I'm still waiting for the motor driver. . .. . ahhhh damn Ever Given :smiley:

Anyway, I started coding, and I do have an issue :confused:

Here is the code :

//Bluetooth HC-05
#include <SoftwareSerial.h>

//nRF24   MISO12 - MOSI11 - CLK13 - CE7 - CSN8


//595 shift
#define data 16   //A2 D16         
#define latch 15  //A1 D15
#define clk 14   //A0 D14

//other
#define laser 18
#define buzzer 19
// 17 prazno, A3

byte leds = B00000000; //bitovi su nule u startu
void registarM() {
  digitalWrite(latch, LOW);
  shiftOut(data, clk, MSBFIRST, leds);   //MSB (skroz levo) jedan smer
  digitalWrite(latch, HIGH);    //latch HIGH - kopira shift registar u storage registar
}
void registarL() {
  digitalWrite(latch, LOW);
  shiftOut(data, clk, LSBFIRST, leds);   //LSB (skroz desno) drugi smer
  digitalWrite(latch, HIGH);   //latch HIGH - kopira shift registar u storage registar
}
void shiftLeds() {

  byte shiftTempo = 70;  //brzina svetla
  registarM();  //prvi smer
  for (byte x = 0; x < 5; x++) {

    bitClear(leds, x - 1);   //izbrisi prethodni
    bitSet(leds, x);         //upali trenutni
    registarM();               //sprovedi
    delay(shiftTempo);
  }

  leds = 0; // svi u nulu
  registarM(); // potvrdi

  for (byte w = 2; w < 7; w++) {  //sad idemo suprotni smer. 2 je treci LED s desna

    if (w == 2) {
      w++;
      continue;
    }
    bitClear(leds, w - 1);
    bitSet(leds, w);
    registarL();
    delay(shiftTempo);
  }
}
void startAnimation() {

  byte leds = B10101000;    // leds prilikom paljenja
  digitalWrite(latch, LOW);
  shiftOut(data, clk, LSBFIRST, leds);   //LSB (skroz desno) drugi smer
  digitalWrite(latch, HIGH);

  for (byte x; x < 5; x++) {
    tone(buzzer, 2000, 40);
    delay(130);
  }

  leds = B01010000;
  digitalWrite(latch, LOW);
  shiftOut(data, clk, LSBFIRST, leds);   //LSB (skroz desno) drugi smer
  digitalWrite(latch, HIGH);

  tone(buzzer, 14000, 400);
  delay(500);
  tone(buzzer, 50, 130);
  delay(130);

  for (int x; x < 400; x += 50) {
    digitalWrite(laser, 1);
    delay(x);
    digitalWrite(laser, 0);
    delay(x / 2);
  }
}

//SoftwareSerial BLT(10, 9);  // the is a problem during startAnimation(); it beeps 40 times . . . no clue 
  
void setup() {
  SoftwareSerial BLT(10, 9);  // no problem during startAnimation();
  pinMode(data, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(clk, OUTPUT);
  pinMode(laser, OUTPUT);
  pinMode(buzzer, OUTPUT);

  BLT.begin(9600);
  BLT.println(" - start - ");

  startAnimation();
  BLT.println(" -ACTIVATED- ");

}

void loop() {

  shiftLeds();
  
}

Here is a link to a video which shows the problem :confused:

if SoftwareSerial BLT(10, 9) is inside setup(), the animation works well, but I can't call BLT.print() in the void loop() [that's logical]
if SoftwareSerial BLT(10, 9) is outside setup() & loop(), something buggy happens. The buzzer starts beeping 50+ times . . . . I don't know why :cry:

So the problem happens before the loop() part. Any suggestion ?

p.s.
the HC-05 Bluetooth is connected and ON
The NRF24 base module is wired to the Nano (except the +5V and GND)

Thanks for the help <3

How are you powering the Bluetooth module?

Doesn't the nrf module require 3.3V?

PaulRB:
How are you powering the Bluetooth module?

Doesn't the nrf module require 3.3V?

There is a LM7805 voltage regulator in the chassis, so 5V is being delivered to the Bluetooth, as well as to the Nano.

The RF24 base module will be fed with cc. 12V (the input of the LM7805), but the power and ground pins are not connected to a power source.

I found a fix. The variable "int x" from the first for() loop is changed to "int a".
I'm using the letter "x" too often when naming simple variables.

void startAnimation() {

  byte leds = B10101000;    // leds prilikom paljenja
  digitalWrite(latch, LOW);
  shiftOut(data, clk, LSBFIRST, leds);   //LSB (skroz desno) drugi smer
  digitalWrite(latch, HIGH);

  for (byte a=0; a < 5; a++) {
    tone(buzzer, 2000, 40);
    delay(130);
  }

  leds = B01010000;
  digitalWrite(latch, LOW);
  shiftOut(data, clk, LSBFIRST, leds);   //LSB (skroz desno) drugi smer
  digitalWrite(latch, HIGH);

  tone(buzzer, 14000, 400);
  delay(500);
  tone(buzzer, 50, 130);
  delay(130);

  for (int x; x < 400; x += 50) {
    digitalWrite(laser, 1);
    delay(x);
    digitalWrite(laser, 0);
    delay(x / 2);
  }
}

Now it works :slight_smile: :-*

I'm using the letter "x" too often when naming simple variables.

No, I don't think that's it. You can use x as many times as you like.

I think the real fix is that before, you did not give an initial value of zero;

  for (byte x; x < 5; x++) {
    tone(buzzer, 2000, 40);
    delay(130);
  }

so it starts as some arbitary value like -45, and repeats 50 times before the loop ends. But now you are initialising it to zero, so it works as intended.

  for (byte a=0; a < 5; a++) {
    tone(buzzer, 2000, 40);
    delay(130);
  }

PaulRB - Your conclusion is correct, if I assign the value 0 to the counter (x or a) it works well. Thanks !
I thought that if an int or byte variable hasn't been assigned a value, by default it will be zero

Like int x and int x = 0 are the same thing.

Dacha011:
I thought that if an int or byte variable hasn't been assigned a value, by default it is zero

It's not guaranteed to be zero. I think it depends on the "scope" of the variable.

Global variables get assigned some memory before the sketch begins running, and keep that memory until power-off or reset. But I think all memory is set to zero after the Arduino is powered on or reset, and the result is that global variables always seem to reliably zero by default.

But local variables, those declared inside functions and loops, get assigned some memory when the function or loop starts, and that memory then gets released when the function or loop ends and can get re-cycled/re-used by other functions or loops. So it's not guaranteed to be zero.

It's probably safest to always initialise your variables!

Thanks PaulRB ! I will remember that.

PaulRB:
But I think all memory is set to zero after the Arduino is powered on or reset, and the result is that global variables always seem to reliably zero by default.

IO registers will be reinitialized after reset, but I don't think your normal SRAM is. Global variables are initialized not because of a hardware feature, but because the language standard requires them to be. It's part of the unseen code created by the compiler that runs before any of your programs' code (not just the sketch, but before the Arduino core code too) runs.

I believe class and struct members will also be default initialized if an initial value is provided for them. I believe it's only local non-static primitive types that don't get automatic default initialization.

The fact that default initialization is not automatic in all cases is a good reason to be in the habit of initializing every variable you declare. It will never hurt you to do so, and makes explicit exactly what values your using to whoever comes after you looking at the code (and you in 6 months will not remember much, I promise you). Also saves you from remembering the rules wrong and accidentally not initializing something you should have, although I think compilers gives warnings for this kind of thing if you turn them on.

Global variables are initialized not because of a hardware feature, but because the language standard requires them to be.

+1 karma for that clarification!

@Jiggy-Ninja
Thanks for the useful info !

Finally, the project is complete !


I also made a phone app to control the robots using a joystick on my screen (Bluetooth). (Sorry, it's in Serbian). 6 buttons are on the left, and an x/y axis joystick is on the right.

The nRF24 module is working great as well. I'm using two slide potentiometers to get values for both electro motors. It's much easier to manoeuvre this way, compared to the joystick app on my phone.
The only downside is that I have to assemble this controller to send the signals this way.

All in all - this was an interesting project :slight_smile:
Thanks for the help and support <3

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.