Show Posts
Pages: 1 ... 79 80 [81] 82 83 ... 98
1201  Topics / Education and Teaching / simple explanation of shift register use. on: April 25, 2011, 11:03:01 am

I had to try and explain what a serial in parallel out shift register does, and came up with this, which might be of some use to newcomers.

A postman ( mailman ) has to deliver 10 parcels to 10 houses in a row, he can only carry one at a time, so to save a lot of walking,  he comes up with the idea of parking at the end house and tooting his horn ( taking the latch pin low ) to call the people out of their houses to their front gardens.

 He then gives the parcel for the furthest house to the lady at the first house, and asks her  ( taking the shift register clock high and low again ) to pass it to the next lady.

He then gives her the second parcel and shouts to everyone to pass them on ( pulsing  the shift clock again )

When all the parcels have been passed out , he tells them to take them indoors and open them ( by taking the latch pin high again )

In practice this save a lot of wiring ( walking )  and a great many devices can be connected to shift data to the right device, such as LED displays which would need thousands of individual wires to light the correct patterns.
1202  Using Arduino / Project Guidance / using function repeatedly on: April 25, 2011, 10:11:06 am
I have wasted a day on this, I have before used a function to calculate a result using the same integers and just reloading the information and generating an answer.

I am obviously doing something stupid. I have posted the Mk 999 version below, it has changed many times today..

This time I am trying to scan the commons of 5 BCD switches, by sequentially taking pins 7,8,9 13, and 14 low, and feeding the 4 binary contacts ( through diodes ) to the pins 3 ,4 , 5 and 6  and saving the number as       msg [n]  = address.  for sending by Virtual Wire.

I tried it with linking a wire between 6 and 14 which gives me the predicted 7 on the first loop, and then 15 for the next loops.

When I print the pins it is right , but the address always want to give 15.

I could do it separately, but its bugging me because I have been having some success with functions and arrays lately..  Time to phone a friend :-)

#include <VirtualWire.h>    // Wireless transmitter/receiver library
#include <avr/sleep.h>      // powerdown library
#include <avr/interrupt.h>  // interrupts library
// ***********************************************************************
int SW0 = 3;               // bits to read from BCD switches - LSB
int SW1= 4;               // bits to read from BCD switches
int SW2 = 5;               // bits to read from BCD switches
int SW3 = 6;               // bits to read from BCD switches - MSB

int add0;                  // address bits read from switches
int add1;
int add2;
int add3;

int comUnit = 7;    //  outputs to common contacts of the BCD switches
int comTens = 8;
int comHund = 9;
int comThou = 13;
int comAddr = 14;

int comcount;
//int switchbanks = 5;  // change here for number of switches in unit

int pin2 = 2;               // Int0 interrupt pin,  refresh button to ground
int address = 0;            // bits put together afteer reading switches

char msg [5]; // extra char added for address
void checkdata () // read and put together bytes function
  add3 = digitalRead(SW3); // shift it left 3 places
  add3 = add3 << 3;
  add2 = digitalRead(SW2);
  // shift it left 2 places
  add2 = add2 << 2;
  add1 = digitalRead(SW1);
  // shift it left 1 place
  add1 = add1 << 1;
  add0 = digitalRead(SW0);
  // now OR it together
  address = address|add3;
  address = address|add2;
  address = address|add1;
  address = address|add0;
  Serial.print("data for switchbank ");
  int n = comcount;
  msg [n]  = address;
// *  Name:        pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
  /* This brings us back from sleep. */
// *  Name:        enterSleep
void enterSleep()
  /* Setup pin2 as an interrupt and attach handler. */
  attachInterrupt(0, pin2Interrupt, LOW);
  delay(50); // need this?
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
  sleep_enable();                       // setting up for sleep ...
  ADCSRA &= ~(1 << ADEN);
  PRR = 0xFF;

  sleep_mode();                         // now goes to Sleep and waits for the interrupt

  /* The program will continue from here after the interrupt. */
  detachInterrupt(0);                 //disable interrupts while we get ready to read the keypad
  PRR = 0x00;
  /* First thing to do is disable sleep. */
  digitalWrite(comUnit, HIGH);
  digitalWrite(comTens, HIGH);
  digitalWrite(comHund, HIGH);
  digitalWrite(comThou, HIGH);
  digitalWrite(comAddr, HIGH);

// ***********************************************************************
// set up the pins as Inputs, Outputs, etc.
void setup()

  pinMode  (comUnit, OUTPUT );
  pinMode ( comTens, OUTPUT) ;
  pinMode ( comHund , OUTPUT) ;
  pinMode ( comThou , OUTPUT) ;
  pinMode ( comAddr , OUTPUT) ;

  /* Setup the pin directions, write inputs High to turn on internal pullups */

  pinMode(pin2, INPUT);                 // our sleep interrupt pin
  digitalWrite(pin2, HIGH);
    // puts all BCD inputs to input with pullups
  pinMode(SW0, INPUT); // LSB of remote Address
  digitalWrite(SW0, HIGH);
  // byte add0 = 0; // read the value of SW0
  pinMode(SW1, INPUT); // LSB+1
  digitalWrite(SW1, HIGH);
  // byte add1= 0;
  pinMode(SW2, INPUT);  // LSB+2
  digitalWrite(SW2, HIGH);
  //  byte add2 = 0;
  pinMode(SW3, INPUT);  // MSB of address
  digitalWrite(SW3, HIGH);
  //  byte add3 = 0;

  // Initialise the IO and ISR for VirtualWire
  vw_setup(4000);                      // Bits per sec - had to double from 2000 with 8MHz 3.3V Pro-Mini
}                                            // end of void Setup()
void loop()
  //               wakes up here
  for (int comcount=0; comcount<=5; comcount++ ) {
    switch (comcount)
    case 0:
      digitalWrite (comAddr, LOW);    
      checkdata ();    
     // msg [0]  = address;
      digitalWrite (comAddr, HIGH);
    case 1:
      digitalWrite (comThou, LOW);    
      checkdata ();    
     // msg [1]  = address;
      digitalWrite (comThou, HIGH);
    case 2:
      digitalWrite (comHund, LOW);    
      checkdata ();    
     // msg [2]  = address;
      digitalWrite (comHund, HIGH);
    case 3:
      digitalWrite (comTens, LOW);    
      checkdata ();    
     // msg [3]  = address;
      digitalWrite (comTens, HIGH);
    case 4:
      digitalWrite (comUnit, LOW);    
      checkdata ();    
    //  msg [4]  = address;
      digitalWrite (comUnit, HIGH);
    case 5:
      enterSleep ();
    }  // end of switch function
  }  //   end of comcount 1-4

  vw_send((uint8_t *)msg, 5);     // send the character out
  //Serial.println(key);                // for debugging only
  vw_wait_tx();                             // Wait until the whole message is gone
  delay (50);
// end of void loop

1203  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: April 22, 2011, 01:52:32 pm
I used to use a separate HT12D chip in each unit to be controlled, and by sequencing through the addresses as described, I would update ( and latch ) each unit in turn.

It was rather slow but worked very well.  That is why I thought of using the same encoding/decoding sytem, but with the arduino scanning the addresses.

I have now been dragged into the 21st century and I am going over to using Arduino at both ends.

I  have developed a system using the VirtualWire library, which seems to be working fine, if there are any problems in trials I can easily make it repeat the code say 5 times, and look for the same decoded data 3 times, much the same as with the HT12.
1204  Using Arduino / Storage / Re: Interfacing SD card's to the Arduino and stability - a few tips..... on: April 18, 2011, 03:29:00 pm
thanks kalem,   I have been having some fun and games with an intermittent  SD card,   I halved its speed to solve my problem but I will I put another 100nF across 3&4 of the holder to make sure.
1205  Using Arduino / Project Guidance / Re: Tone library and millis clash? on: April 18, 2011, 06:24:05 am
1206  Using Arduino / Project Guidance / Re: pin 2 pullup res on: April 18, 2011, 06:20:12 am
Thanks, it did seem odd when there are pull ups in the chip... I have seen it mentioned several times.
1207  Using Arduino / Project Guidance / pin 2 pullup res on: April 17, 2011, 02:38:58 am
On a freestanding board I saw it is recommended to put a 10 k pullup resistor from pin2 to Vcc to avoid noise.

Can I just set it to an input and take it high to enable the internal pullup?  
1208  Development / Suggestions for the Arduino Project / Re: Basic suggestions for IDE usability improvements on: April 17, 2011, 02:35:39 am
The active port would be very handy,  I have been developing a telemetry system with 2 arduinos plugged in to the one PC, and I keep ending up with 2 receivers or 2 transmitters when I forget to swap the port.
1209  Using Arduino / Project Guidance / Re: Tone library and millis clash? on: April 17, 2011, 02:30:55 am
I think just one, I want to make a horn type sound for the end of a timeout period, a square wave into a fet amp and speaker.
Not worried about distortion, just lots of noise ( that's what my late Dad used to say about the Beatles :-) )
1210  Using Arduino / Project Guidance / Tone library and millis clash? on: April 17, 2011, 01:22:03 am

In the description of the Tone library, it states:-

" Also, although it's the last timer to be allocated, timer 0 (which is used for millis() among other things) will be affected if used. "

Does this mean only while the tone is playing?  or will my timing of my project which uses the millis for a countdown timer be compromised by merely calling up the tone library?

I want to sound a horn at the end of the countdown, so I dont need the timer then..  I just need confirmation
1211  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 16, 2011, 05:10:01 pm
Right thanks everyone, its working !

And a stupid thing I had forgotten was that when it was just counting down seconds, I was worried about losing the first second, so I started the clock from 24.9 seconds for the 24 second timer.
This was because as soon as you hit "run" it would flick over to 23, but the horn would sound ( and the pause would go high )as soon as the count went from 1 to 0, so it was running for only 23 seconds.  ( imagine if I wanted a 2 second countdown - it would be 1 second )

I am now counting down in 10ths of a second, and displaying the last ten seconds as 9.9 etc, so the 0 doesn't happen until a second after the 1 has changed to 0.9 and it counts right down to 0.0 .

So now I start at the "proper" 24 secs.   It pauses and restarts from the fraction of a second fine too.

1212  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 09:29:14 pm
right, I see now, I will give it a try, thanks
1213  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 08:49:14 pm
Thanks Rob
I will try that code, I do define the array msg as 4 in the setup, is that part of it?

I will stick the scope on and see what the transmission length is, I should have done that anyway.

I will also look up the hex/dec story  when I get a chance ( 4am and I am soldering hundreds of LEDs for a rush job! )

1214  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 04:46:34 am
Thanks, that makes sense now, so much to learn, so little time
1215  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 15, 2011, 04:15:03 am
   tens = (secNibble10) ? digitTable [ secNibble10] : 0; // leading zero blanking
  units = digitTable [secNibble];
  units |= ( period) ? B10000000 : 0;

Whats the question mark ?   I am trying to understand this part...
Pages: 1 ... 79 80 [81] 82 83 ... 98