Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Is uint8_t equivalent to byte, etc.? on: December 27, 2013, 06:50:51 pm

Thanks Michael for taking time to explain this to me!
If I understand you correctly, I should start using 'uint8_t', etc,  forms for portability.
I have been using byte, int, etc. because is faster to type.
I guess this 'old dog' needs to learn some new tricks!

Again, thanks for your explanation!
2  Using Arduino / Programming Questions / Is uint8_t equivalent to byte, etc.? on: December 27, 2013, 11:55:42 am
   I am coming to Arduino from micro-processors that use various flavors of BASIC,
   and am somewhat confused about number data types.

   In some places I see 'uint8_t'  and in other places I see 'byte'. 
   After reading various library *.cpp and *.h files, they use uint8_t,  etc.
   On the Arduino Reference page they describe data types: byte, int , word, etc.

   From searching this Forum and online, I have not found a definitive explanation.
   From my research, my understanding so far is:

         byte OR  uint8_t =  8-bit unsigned, 0 to 255

          int OR  int16_t = 16-bit   signed, -32,768 to 32,767
        short OR  int16_t = 16-bit   signed, -32,768 to 32,767 (Same as int)
 unsigned int OR uint16_t = 16-bit unsigned, 0 to 65,535
         word OR uint16_t = 16-bit unsigned, 0 to 65,535 (Same as unsigned int)

         long OR  int32_t = 32-bit   signed, -2,147,483,648 to 2,147,483,647.
unsigned long OR uint32_t = 32 bit unsigned, 0 to 4,294,967,295

   Is one form better than the other? Please let me know if my understanding is correct.
   A short explanation will be greatly appreciated!!
   Thanks in advance! I apologize if this is too basic of a question.
3  Using Arduino / Programming Questions / Re: problem with rtc ds1307 code on: August 16, 2013, 10:35:00 am
I have tried all of the available libraries for real time clocks, rtc. I could not get any of them to function as I wanted.
After studying the libraries, I found that the libraries made accessing rtc's more complicated than necessary.

Years ago, I wrote a BASIC program for a Basic Stamp micro-controller to access a rtc module, so I ported it to Arduino.
Using the Wire library, it is surprisingly easy to access a rtc.

Later I purchased a new module with battery backup, I did not want to keep setting the time and date.
I have rewritten my rtc sketch to access the new module. This module uses a DS3232 chip which is very similar to the DS1307.
The first seven addresses are identical:  seconds, minutes, hours, Day of Week(1 - 7), Day of Month(1 - 31), month, year.
The DS3232 has gained only 9 seconds in 192 days of operation, most of which was on battery backup.

I use a Arduino Mega because it has 3 extra serial ports. I use one of these extra ports for a serial lcd to display the time and other data.
My lcd is a Modern Device serial display (LCD117), it has a easy to learn command set and only uses one wire to connect to a serial port.

Let me know if your would like me to post my rtc sketch.

4  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 11, 2013, 03:30:03 pm
Thanks for confirming my suspicion. I appreciate your feedback.

I seem to learn best by trial and error, also known as fumbling around !

I am a disabled veteran. One thing I have a lot of is time.

Programming helps take my mind off of negative things.
5  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 11, 2013, 11:22:33 am
Thanks for your reply.

I narrowed my issue somewhat.
When sizeof() is used directly on an array, it returns the correct size.

However, when I pass an array to a function THEN use sizeof(), it returns 2.
I am thinking that sizeof() is returning the size of the pointer. Not sure about this.

Reading online C tutorials concerning passing arrays to functions, they say in passing an array
to a function you are in fact passing a pointer. Still learning about pointers.

My goal is for this program to receive a single input using a keypad or button to input a pattern selection.
Currently, I am modifying my code so the input function will take a number, in a limited range, using switch . . . case.
Switch . . . case  assigns a pointer to the specified pattern array, sizes the array then passes pointer and size to the output function.

As I stated in a previous post, I am new to this programming language.

I am having so much fun learning this language.
I can see so many possibilities that were not available when I was using various flavors of Basic.

Thanks again for your help!

6  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 10, 2013, 09:03:29 pm
I constructed my patterns in binary first, then convert to hex.
I got tired of scrolling thru lines of data.
Using hex data only saves space in your code, not the compiled sketch.


  data[] = {0000 0000,  // =  0x00
                1000 0001,  // =  0x81
                0100 0010,  // =  0x42
                0010 0100,  // =  0x24
                0001 1000,  // =  0x18
                . . . . . . . .}

  data[] = {0x00,0x81,0x42,0x24,0x18, . . };
  Some of my patterns have 30 elements.

  One line of data versus 32 lines makes easier code reading.

7  Using Arduino / LEDs and Multiplexing / Re: 595 patterns on: January 10, 2013, 07:01:49 pm
Hi everyone!

I am new to Arduino and this Forum. I am retired military and like to program uMicroProcessors & build robots/projects
that actually do something. Who says you can't teach an old dog new tricks!

I have been working on a project very similar to this thread. Using 74HC595 shift register to control Christmas lights.
I had already written programs in Basic for other uProcessors, so I have been trying to port those programs to Arduino.
I have not worked with C before, so this has been very interesting.

My goal is to construct very small control units to control multiple strings of LED Christmas lights.

Attached is one of my first sketch to implement this goal. ( It functions properly. )
For testing, I have the shift register connected to 8 LEDs of a 10 LED bar graph, so I can visualize the patterns.
I have also tested this sketch with my relay boards.

In this sketch, I pass a pattern array, and its size, to a function for display through a shift register.
I have been trying to use the utility function 'sizeof()' without success.
Every time I have used 'sizeof()', it returns the value '2' regardless of the size of the array.
The C programming tutorials that I have been studying says in passing an array to a function, you need to pass the size of the array as well.

Am I missing something? Is there a issue with 'sizeof()' ?
Could someone show me an example of proper use of 'sizeof()' that actually returns the correct size of an array?
If I can get 'sizeof()' to work, I can simplify my function & sketch.

I apologize in advance for any breach of protocol. Just let me know what I need to do to comply with Forum standards.

P.S. I Love this stuff !!
//======================= this line is 80 chars long ==========================
  Program Name: _74HC595
        Author: Paul Fogle
          Date: 01/05/2013
      Modified: 01/10/2013
          Goal: Use 74HC595 shift register to control Christmas light relays.
                Input pattern array number and pass to ChristmasLightRelay()
                function .
  byte Pattern_0[2] = {0xAA, 0x55};
  // every other, alternate
  byte Pattern_1[4] = {0x18,0x24,0x42,0x81};
  // middle out
  byte Pattern_2[6] = {0x81,0x42,0x24,0x18,0x24,0x42};
  // ends to middle, bounce single
  byte Pattern_3[9] = {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  // left to right, all on repeat
  byte Pattern_4[15] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f,
  // left to right, all on exit right
  byte Pattern_5[15] = {0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,0xfe,0xfc,0xf8,
  // opposite of Pattern 4
  byte Pattern_6[30] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f,0x1f,
  // left to right bounce right to left
  byte Pattern_7[7] = {0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81};
  // ends to middle, all on
  byte sizePattern_0 = 2;   // size of pattern 0
  byte sizePattern_1 = 4;   // size of pattern 1
  byte sizePattern_2 = 6;   // size of pattern 2
  byte sizePattern_3 = 9;   // size of pattern 3
  byte sizePattern_4 = 15;  // size of pattern 4
  byte sizePattern_5 = 15;  // size of pattern 5
  byte sizePattern_6 = 30;  // size of pattern 6
  byte sizePattern_7 = 7;   // size of pattern 7

  int delayDur = 150;       // display speed in light pattern
  int latchpin = 8;         // green connect to pin 12 on shift register
  int clockpin = 12;        // white connect to pin 11 on shift register
  int datapin = 11;         // black connect to pin 14 on shift register
void setup()
   Serial.begin(9600);        // com to computer
   Serial1.begin(9600);       // pin 18 ModernDevice Lcd
   pinMode(latchpin, OUTPUT); // pin 12, shift register
   pinMode(clockpin, OUTPUT); // pin 11, shift register
   pinMode(datapin, OUTPUT);  // pin 14, shift register
void loop()
  LightRelay(Pattern_6, sizePattern_6);    // call function to output pattern
// I have tried to use the sizeof() utility without success, it always returns
// 2 on every array that I have tried, so I pass a size variable (tempSize) to
// the function.
void LightRelay(byte *temp, byte tempSize) // output pattern to shift register
{  for (byte x = 0; x < tempSize; x++)
    digitalWrite(latchpin, LOW);                    // enable data write
    shiftOut(datapin, clockpin, MSBFIRST, temp[x]); // data write
    digitalWrite(latchpin, HIGH);                   // disable data write
    delay(delayDur);                                // display speed
    Serial1.print("?x00?y0Size of array: ?x15");    // print to lcd
    Serial1.print(tempSize);                        // print to lcd
void SetupLcd()
  Serial1.print("?G420?c0?f?x05?y3HELLO PAUL"); // print to lcd
  delay(2000);                                  // pause so I can read my name

Pages: [1]