Controlling multiple 7 segment displays

Yes.. That was me who reported that problem earlier. But I tested it later times. It did no happen so. I do not know any friend who ownes an arduino.

I have an ATMega328 chip which i bought for the project (without boot loader in it). Just thinking of replacing the one on the Arduino with this one to check if PC is detecting.

Regards, S.Sudharsan

harisudharsan:
I do not know any friend who ownes an arduino.

Perhaps someone on this forum is close to your home.

harisudharsan:
I have an ATMega328 chip which i bought for the project (without boot loader in it). Just thinking of replacing the one on the Arduino with this one to check if PC is detecting.

That is no use. You need a working Arduino, or some other programmer such as USBasp to burn the bootloader onto the '328. Without the bootloader, the PC will not recognise it.

OOPS :confused: :slightly_frowning_face:

Let me find out then…

Btw, I am not sure if a pic would be helpful at this point as the problem is with Arduino… But here it goes…

Thank you very much Paul for helping me out…

Regards,
S.Sudharsan

You were correct. The pic was not very helpful.

Here is a test you can perform. Remove the atmega chip from the Arduino board and use a wire to connect the rx and tx pins on the atmega socket. This page will show you which pins they are. Use thin wires to avoid damaging the socket. Then open the serial monitor in the ide. Type some characters. When you press enter, your typed characters should be echoed back.This is called a "loop-back test" and will prove that the usb to serial chip on the atmega board is working.

Hi Paul,

I tried to explore more on loop back test to understand more about it. It looks like we also have to ground the reset pin. Would you recommend that too ??

http://forum.arduino.cc/index.php?topic=73748.0

With Regards, S. Sudharsan

harisudharsan:
It looks like we also have to ground the reset pin. Would you recommend that too ??

My suggestion was to physically remove the atmega chip before performing the test. This is not possible on many types of Arduino boards, but you can do it with your board. With the chip removed, there is no reason to ground the reset pin. You only need to do that if you cannot remove the chip.

So you have the choice. Either remove the chip or leave the chip in place and ground the reset pin.

Hi Paul,

A good news. !! Not sure how… My gear is getting detected now… :smiley:

And also i am able to upload new sketches. Actually when I hit with the problem, for some reason, it was listing out only COM3 on the IDE. Having no other option, I selected COM3 assuming the Arduino will be in COM3. Now I can able to see all other COM ports on IDE along with “COM20(Arduino Uno)” option. However It was a very good information i came to learn about the loop back test.

Now I request your help on 2 things.

  1. I have another Atmega328 which I had bought for a project purpose. Wanted to upload arduino boot loader on to it (as a backup. If in case I corrupt the boot loader).

  2. I uploaded the below sketch to it for controlling 2 7 segment displays. Building a water level circuit for 3 individual water tanks. Planning to use analog pins for finding the water level with probes having different amount of resistance for each level sensors and also a buzzer for alert in case of water over flow or under run in any of the tank and a reset switch to stop the buzzer from sounding.

For testing the hard wire connection, I try to upload the below sketch which will display same data on both 7 segment. But for some reason i see the display connected on to the pin 6 of arduino is working great. But the display connected to pin 10 is not working. Do you see any obvious bug in my sketch ?

int latchPin=5;
int LevelDataPin=6;
int TankDataPin=10;
int clockPin=7;


int animate[9]={63,95,126,125,63,111,119,123,63};
int hello[5]={9,6,71,71,64};
int n;

void setup() {
  // put your setup code here, to run once:
  pinMode(latchPin, OUTPUT);
  pinMode(LevelDataPin, OUTPUT);
  pinMode(TankDataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  animation();
  hellog();
}

void animation() {
  for (n=0; n<=8; n++)
  {
    digitalWrite(latchPin, LOW);
    shiftOut(TankDataPin, clockPin, MSBFIRST, animate[n]);
    shiftOut(LevelDataPin, clockPin, MSBFIRST, animate[n]);
    digitalWrite(latchPin, HIGH);
    delay(200);
  }
}

void hellog()
{
 for (n=0; n<=4; n++)
  {
    digitalWrite(latchPin, LOW);
    shiftOut(TankDataPin, clockPin, MSBFIRST, 127);
    shiftOut(LevelDataPin, clockPin, MSBFIRST, 127);
    digitalWrite(latchPin, HIGH);
    delay(50);
    
    digitalWrite(latchPin, LOW);
    shiftOut(TankDataPin, clockPin, MSBFIRST, hello[n]);
    shiftOut(LevelDataPin, clockPin, MSBFIRST, hello[n]);
    digitalWrite(latchPin, HIGH);
    delay(1000);
  } 
}

void loop() {
  // put your main code here, to run repeatedly:
    digitalWrite(latchPin, LOW);
    shiftOut(TankDataPin, clockPin, MSBFIRST, 9);
    shiftOut(LevelDataPin, clockPin, MSBFIRST, 9);
    digitalWrite(latchPin, HIGH);
}

Thanks in advance,
S. Sudharsan

harisudharsan: 1. I have another Atmega328 which I had bought for a project purpose. Wanted to upload arduino boot loader on to it (as a backup. If in case I corrupt the boot loader).

OK, so what help do you need? There is a tutorial on the Arduino playground about how to use an Ardunino to burn the bootloader into an atmega328 chip.

Now that you have described your project in more detail, I can tell you that you will not need the full 16MHz speed of the standard Arduino, and you do not need highly accurate or stable timing, so you could run your standalone atmega at 8MHz and use the 8MHz version of the bootloader. This means can use the atmega chip to run your displays & sensors and keep your Uno for future projects. If you do that, you will not need an external crystal, and you will have the choice to run the chip at either 5V or 3.3V, which makes powering the circuit from batteries easier if that is what you want.

However, if you want to use this chip as a replacement for the chip on the Uno, you must use the 16MHz bootloader, and if you then use that chip to run the project, you will need to have an external crystal and run at 5V (not 3.3V).

Of course, you can change your mind later and re-burn 8MHz or 16MHz bootloaders at any time.

harisudharsan: 2... Do you see any obvious bug in my sketch ?

Yes, I think I can see the problem. You seem to have two separate data pins for the two shift registers but you are sharing the same clock and latch pins between both shift registers. This will not work as you intended. If you need to use separate data pins, you must also use separate clock and latch pins. However, I do not believe you do need to use separate data pins. Instead, you should connect the data-out pin on the first shift register to the data-in pin on the second shift regsiter. You will only need 3 connections to the Uno (plus 5V and GND).

This is called "daisy-chaining" the two shift registers. Your first shiftOut() will send the data to the first shift register, but you will not change the latch pin at that point. Then your second shiftout() will cause the data in the first shift register to be passed to the second shift register, at the same time as the new data arrives from the Uno. Then you use the latch pin to inform both shift registers that the data is ready.

Paul, You are The man !! You exactly got what I wanted.

In fact for this purpose I thought of Using ATTiny or any thing else that would solve this purpose as using an Arduino for this purpose is kind of under utilizing it's efficiency. But I could't wait more to see my first arduino project in action :)

At this point can you help me to calculate the resistance value i shall use in the probes ? i want to have 6 probes for detecting water level. The prob on the lowest level will offer more resistance and gradually the resistance will decrease as the water level raise up. I understand that we can have small or large value resistance added to the probes so that we can have small band width for each probe. or we can have a large resistance added and have a bigger bandwidth for analog read. But I am not sure which is the best option.

Please also do suggest if there is a better option. I found an ulrasonic distance sensor HCSR04. But I wanted to avoid it as the water vapors may damage in the course of usage. (This is a real time project)

With Regards, S. Sudharsan

The water vapour/liquid will corrode your probes over time, especially if a small current flows between them. So this may not be a more reliable solution than the ultrasonic sensor.

To minimise the corrosion of the probes, use an Arduino digital pin to supply the voltage to the probe just before taking the analog reading. Then remove the supply to the probe after the reading has been taken. Take readings only every few minutes/hours as needed.

I can not suggest a resistor value. It depends on so many factors, like how the probes are constructed etc. What i can say is that the value of the probe plus the series resistor should be around 5K to 50K. Less than this will waste current and cause corrosion of the probe. More than this will give noise in the readings taken by the Arduino analog input.

Hi Paul,

I tried a bit of Object Oritented programming… Just wanted to ensure my flow is correct. The code is not yet fully ready. I want to have the tank count it can control to be dynamic. Any number between 1 to 6 although in normal case it may not go to that extent. But currently I am assuming the count to be 3. When there is some reading in the analog in during the startup, then i assume it is connected to a sensor.

Note: I am sure writing the class definition along with with implementation in a single file is not the best practice. But at this point I feel this is not a complex code to handle. So having it in same file for convenience.

int latchPin=5;
int DataPin=6;
int clockPin=7;

//Below method is for displaying welcome message
void Hellog()
{
  int hello[5]={9,6,71,71,64};
  int n;

  for (n=0; n<=4; n++)
  {
    digitalWrite(latchPin, LOW);
    shiftOut(DataPin, clockPin, MSBFIRST, 127);
    shiftOut(DataPin, clockPin, MSBFIRST, 127);
    digitalWrite(latchPin, HIGH);
    delay(50);
    
    digitalWrite(latchPin, LOW);
    shiftOut(DataPin, clockPin, MSBFIRST, hello[n]);
    shiftOut(DataPin, clockPin, MSBFIRST, hello[n]);
    digitalWrite(latchPin, HIGH);
    delay(1000);
  }
}

class Tank
{
  public: int TankNumber, CurrentLevel=0, Min=0, Max=5;
  int WaterLevelReadPin;
  void ReadWaterLevel()
  {
    //Analog read for CurrentLevel goes here
    //<<<<<< Yet to write the coding for this>>>>>>>

    if( CurrentLevel > (Min + 1) || CurrentLevel < (Max-1) )
    {
      /* More bothered when the water level is about to over flow or under run. 
      So adding 5 minutes delay when not either of the case to avoid
      too frequent water level detection routine */
      
      delay (300000); // Adding 5 minutes delay
    }
    
  }
  void DisplayWaterLevel()
  {
    digitalWrite(latchPin, LOW);
    shiftOut(DataPin, clockPin, MSBFIRST, TankNumber);
    shiftOut(DataPin, clockPin, MSBFIRST, CurrentLevel);
    digitalWrite(latchPin, HIGH);
    delay(5000);
  }
} tank[6];

///////////////////////////////////////////////////////////
//
//     Main Program Starts Here
//
///////////////////////////////////////////////////////////
int TankCount=3; // Current assumption

void setup() 
{
  tank[0].WaterLevelReadPin=A0;tank[1].WaterLevelReadPin=A1;tank[2].WaterLevelReadPin=A2;
  tank[3].WaterLevelReadPin=A3;tank[4].WaterLevelReadPin=A4;tank[5].WaterLevelReadPin=A5;
  Hellog(); 
  for (int i=0; i<TankCount; i++)
  {
    tank[TankCount].TankNumber=i+1;
  }
}

void loop() 
{
  for (int i=0; i<TankCount; i++)
  {
    tank[TankCount].ReadWaterLevel();
    tank[TankCount].DisplayWaterLevel();
  }
}

With Regards,
S.Sudharsan

Hi. You should learn about the principles of object orientation. If you are not following the principles, you are not truly writing OO code, even if you are using some of the C++ OO contructs.

      delay (300000); // Adding 5 minutes delay

What do you think the Arduino will be doing during this 5 minute period? Remember there is only one cpu core and no multi-threading.

Hi Paul,

Thanks for high lighting that. I will fix it and comeback !

Regards, S.Sudhasan

Hi Paul,

A question for the sake of knowledge. May I know how to read inputs from multiple inputs from various sensors connected to Arduino ? For example, I have 20 LDRs from which i wanted to read the inputs from, May i know how we achieve this using arduino ?

I am sure, we must use some addressing mechanism to individually identify each sensor. But how is this achieved normally?? May be a pointer about it at this time would be good. I shall do some background work on it and comeback if I have any question.

Regards, S.Sudharsan

If you had only a few analog sensors, you would simply connect one to each analog pin and read from that pin with analogRead(pin_number);. So I will assume your question refers to the situation where you have more analog sensors than the Arduino has analog inputs.

There are many methods. Here are three:

  1. Use an i2c Analog-To-Digital convertor chip. There are various models with between 1 and 16 analog channels. Often you can connect several of these chips to the same two pins of the Arduino (SCA and SCL - the i2c bus).

  2. Use analog multiplexer chips. These allow you to connect multiple analog sensors to the same Arduino analog pin. You also connect some Arduino digital pins to the multiplexer to allow the sketch to select which sensor is connected to the analog pin at any instant.

  3. For large numbers of simple sensors like LDRs, it may be possible to arrange the sensors in a matrix (with diodes to prevent currents flowing the wrong way through the matrix). The rows and columns of the matrix would be connected to a combination of analog and digital pins on the Arduino. You can then write a sketch to scan the matrix row-by-row and column-by-column, reading the sensor at each position in the matrix.

Thanks for the reply Paul.

Actually I was quoting LDR just to explain my question well. But my actual requirement is not just LDR. This is the background work for my next project. (After the water level indicator)

Actually I want to build a clock with arduino which is not just a clock.

It must have features to....

  • Automatically switch on night lamp (a matrix of LEDs) to on and get off when low light is detected. (Using DS3231 as RTC)
  • To have temperature and humidity sensor (Using SHD22 sensor)
  • An volt meter. Planning to use a TFT display as this will be used to display the menus also. 7 segment is only for the time, temperature and humidity
  • Alarm mode.
  • A bunch of LEDs to indicate the day of week and AM/PM led.
  • Ofcourse a buzzer for alarm

Just thinking of adding more innovative simple features as i come across.. Just to make the console more usable. Infact wanted to have feature that can project the time on he wall (Seems to be simple on looking the youtube videos) But that is not my priority at the moment.

Please let me know if the sensors I have choose are good or if i can choose a better sensor. Also let me know any idea that can improvise the project. Also I wanted to know the mechanism to calculate the power required to run the entire system.

I thought of using a 5 Volt 1.0A input for this. (Mobile phone charger input). Wanted to know If that input would be sufficient to run the system. The idea is, the system has to run both using both 5v DC and 250V AC inputs. If it is running in DC, the Voltage information alone will not be available.

Thanks and Regards, S.Sudharsan

DS3231 is a good choice. It is accurate and has a built-in temperature sensor. For humidity, if you choose a sensor with i2c interface, like sht21, it can share the same Arduino pins as the rtc.

TFT is quite an advanced component for your first or second project. I would recommend a 16x2 or 20x4 character lcd. You can buy these also with an i2c interface, so it shares the same pins as the rtc and humidity sensor.

What is the volt meter measuring?

For your lamp, you will need a transistor of some kind, and an external power supply. The Arduino cannot supply enough power for an led matrix lamp. Will you build or buy this lamp? What voltage and current will it need?

Hi Paul,

Thanks for the suggestion..

I wanted to have power to the console in 2 ways. One is using the smart phone mobile charger and another is 220V AC in. When it is running in 220V AC, the console step down it to 5 Volts and rectifies it to DC.

So , when it is running in 220 V ac, Wanted to have the display that will show what is the input AC volt at that point of time.

Lamp is an array of LED lights. May be 3x3 matrix would be good. Planning to give its input directly from the power source to the Arduino. But the Arduino pin would control the complete circuit using an amplifier setup. May be a BC549.

Thanks and Regards, S.Sudharsan

Hi,

A question.. What is the difference between having a DS3231 RTC and having a ATTiny with clock program flashed and a battery connected ?

I mean, i am trying to understand what DS3231 does special that a micro controller do not do ?

Regards, S.Sudharsan

The DS3231 will be far, far more accurate. It should keep time to within a minute or two per year. It has a highly accurate crystal and also has temperature compensation. The ds3231 modules also have a button cell to maintain the clock when there is no power.

Using an attiny you will be lucky if it keeps time to within 2 minutes per day, and accuracy will vary greatly with temperature, supply voltage etc.

You can attach a crystal resonator to an attiny, and if you buy an expensive and accurate crystal, and an accurate temperature sensor, and write some code to maintain the time and compensate for temperature, and make the whole circuit run at very low power so that a button cell can run it for several years, you might get close to the accuracy of the ds3231 module. But you will have spent much more money, much much more time and your circuit will not be as compact.