Show Posts
Pages: 1 ... 80 81 [82] 83 84 ... 100
1216  Using Arduino / LEDs and Multiplexing / Re: scanning 25 bcd switches - wrong reading? on: June 02, 2011, 09:03:55 am
Now I am really confused,  when I connect a binary switch, the data stays the same, and also the clock signal doesnt change....

I think I must strip it down to bare bones and try it
1217  Using Arduino / LEDs and Multiplexing / Re: scanning 25 bcd switches - wrong reading? on: June 02, 2011, 08:18:06 am
when I try that I get:-

invalid conversion from 'uint8_t*'to 'uint8_t'



1218  Using Arduino / LEDs and Multiplexing / Re: scanning 25 bcd switches - wrong reading? on: June 02, 2011, 07:57:06 am
Thanks

I will play around with that and actually hook up a bcd switch to see whats happening.

It seemed to be working with the commented out bit, but of course inverted ( 1111 for all switches off )  but I can always invert it at the RX end anyway.
1219  Using Arduino / LEDs and Multiplexing / Re: scanning 25 bcd switches - wrong reading? on: June 02, 2011, 03:12:15 am
Hi Mike

The outputs of the 4017 have only one high at a time, each output goes to the common of a bcd thumbwheel switch, the 4 switched outputs of the switches have steering diodes so that they don't short out the 4 data lines.
I have used this circuit extensively, but with a cd4514 chip to feed the switches, but that would need 2 of them to do 32 switches, and take 5 pins of the micro for their bcd address, so I want to try it this way with just 2 pins to control as many switches as I like ( I am keeping it down to 25 switches as thats all that the 4017 can cascade, and the VirtualWire can handle only 27 messages.
1220  Using Arduino / LEDs and Multiplexing / Re: scanning 25 bcd switches - wrong reading? on: June 02, 2011, 02:47:46 am
Hi Robert

here's a link to the basic cct for one CD4017 giving 10 switches.  I cant just add the picture as it looks like flikr wants people to go there and look.....

I am using a 16M xtal, and the 4000 baudrate seems to be working fine on all the other projects ( though I slow it to 2400 for the new cheapy transmit / receive pair I have been experimenting with )


http://flic.kr/p/9PB8nm
1221  Using Arduino / LEDs and Multiplexing / scanning 25 bcd switches - wrong reading? on: June 01, 2011, 10:53:44 pm
I am missing something stupid here, I am using 3  cascaded CD4017 decade counters to feed ( up to ) 25 bcd switches.

(I am posting here as it is multiplexing )

The 4 outputs of the switches are fed via diodes to 4 data inputs (  SW0 - 3 ) of the micro, each input has a pull down resistor.

The following code is supposed to send the data from the switches via virtualwire ,  but with no connections to the data inputs - just the pull down resistors I get all  1000 when the ISR is triggered.  i.e :-

TX setup
Sleep
data for switchbank 0 =    1000
data for switchbank 1 =    1000
blah blah
data for switchbank 18 =    1000
data for switchbank 19 =    1000
Sleep


actually I think its trying to tell me something, its 4 am and I should have some rest  smiley-roll-sweat
can anyone see my blonde moment here?

Incidentally, with another chip for the scanning that has zero going outputs to the switches, I inverted the data with the commented out line
 // address |= digitalRead(SW) << i;      and this gives 1111  as expected...............


my code is
Code:
//  FIRST TRY SCANNING USING 4017  

#include <VirtualWire.h>    // Wireless transmitter/receiver library
#include <avr/sleep.h>      // powerdown library
#include <avr/interrupt.h>  // interrupts library

// ***********************************************************************

uint8_t SW[4]; // assign four data pins from bcd switches

int SW0 = 3;               // bits to read in unique address - LSB
int SW1 = 4;               // bits to read in unique address
int SW2 = 5;               // bits to read in unique address
int SW3 = 6;               // bits to read in unique address - MSB

int address = 0;          
int add0;
int add1;
int add2;
int add3;

int reset = 7;
int clock = 8;

int dpin0 = 0;              // apparently redefined by Serial as Serial Monitor works
int dpin1 = 1;              // apparently redefined by Serial as Serial Monitor works
int pin2 = 2;               // Int0 interrupt pin


// create an array to store data to be sent out
// ***********************************************************************
int switchbanks = 19; // CHANGE TO NUMBER OF SWITCHES max 25
char msg [20]; // includes msg 0  which is PIN number from dip switches
// ***********************************************************************

// *  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
  // Power up functions
  PRR = 0x00;
  /* First thing to do is disable sleep. */
  sleep_disable();
}

// ***********************************************************************

void setup()
{

  Serial.begin(9600);

 
  pinMode(pin2, INPUT);                 // our sleep interrupt pin
  digitalWrite(pin2, HIGH);  //  sets pull up res

  pinMode ( reset, OUTPUT );  //  resets the external cd4017 counters to 0
  digitalWrite(reset, HIGH);

  pinMode ( clock, OUTPUT );  // starts the clock to the CD4017s to zero so first out = PIN number
  digitalWrite(clock, LOW);

//***************************************************************************

//  all data inputs SW0-3 have pull down 22k resistors
  pinMode(SW0, INPUT); // LSB of remote Address
  byte add0 = 0;
  pinMode(SW1, INPUT); // LSB+1
  byte add1= 0;
  pinMode(SW2, INPUT);  // LSB+2
  byte add2 = 0;
  pinMode(SW3, INPUT);  // MSB of address
   byte add3 = 0;

// *************************************************************************
  Serial.begin(9600);              
  Serial.println("TX setup");              // for debug only

  // ***********************************************************************t
  // Initialise the IO and ISR for VirtualWire

  vw_set_ptt_pin(10); //  should be set as default ?
  vw_setup(4000);                      // Bits per sec

}                                            // end of void Setup()

// *******************************************************************************************

void loop()
{
digitalWrite(reset, HIGH);

  Serial.println("Sleep");               // for debug only
  
  enterSleep();                             // call Sleep function to put us out
  //  THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep()
  
digitalWrite(reset, LOW);

  scan ();

   vw_send((uint8_t *)msg, switchbanks);     // send the character out
 
  vw_wait_tx();                             // Wait until the whole message is gone
  delay (10);
  
}                                             // end of void loop

//********************************************************************************************
void scan ()
{
  for ( int x=0; x<= switchbanks; x++ )
  {
 digitalWrite(clock, LOW );
 
 delay ( 50 );
    address=0;
  
    for (uint8_t i = 0; i < 4; i++) {  //    read inputs from bcd switches sequenced by CD4017s
     // address |= digitalRead(SW[i]) << i;
      address = digitalRead(SW[i]) << i;
     }
    digitalWrite(clock, HIGH);  //   advances CD4017s ready for next read
  
    Serial.print("data for switchbank ");  
    Serial.print(x);  
    Serial.print(" =    ");
    Serial.println(address, BIN);
    msg [switchbanks]  = address;

  } // end of  for ( int x=2; x<= switchbanks; x==)

}  // end of scan function


1222  Using Arduino / Project Guidance / Re: loops in loops ? on: May 21, 2011, 04:35:25 am
Got it -   compound bitwise or   
 thanks.
1223  Using Arduino / Project Guidance / Re: loops in loops ? on: May 21, 2011, 03:57:27 am
Thanks thats elegant,  but what is the address |=

in

 for (uint8_t i = 0; i < 4; i++) {
      address |= digitalRead(sw) << i;
    }
1224  Using Arduino / Project Guidance / Re: loops in loops ? on: May 20, 2011, 11:00:38 pm

Its a function to read the data from bcd switches, the clock pulse advances a CD4017 whose outputs go to the common of the switches.


Putting the 4 bits together with the OR function is pasted from another sketch that works in many of my sketches, I don't know if there is a simpler bit manipulation way?






Code:


void scan ()
{
    for ( int x=2; x<= switchbanks; x++ )
    {
    digitalWrite(clock, HIGH); 
     
    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;
 
  digitalWrite(clock, LOW); 
 
  Serial.print("data for switchbank ");  Serial.print(switchbank);  Serial.print(" =    ");
  Serial.println(address, BIN);
  msg [switchbanks]  = address;
   
  } // end of  for ( int x=2; x<= switchbanks; x==)

}  // end of scan function
1225  Using Arduino / Project Guidance / loops in loops ? on: May 20, 2011, 06:50:05 pm
I have a strange problem, and just want to verify that a for n= 1 to whatever sequence in a separate function ( subroutine) that it doesnt return to the main loop until it has counted through all n operations ?
1226  Using Arduino / LEDs and Multiplexing / Re: 5 bit binary counter on: May 08, 2011, 06:09:50 pm


I have the same requirements, and solved it as below, with 6 working lines.  The countPins output a normal binary sequence up to whatever is set by "switchbank"


Code:
int counter ;
int count0 ;
int count1 ;
int count2 ;
int count3 ;
int count4 ;

int countPin0 = 7;
int countPin1 = 8;
int countPin2 = 9;
int countPin3 = 13;
int countPin4 = 14;
  int switchbanks = 32;

void setup()
{   
  pinMode(countPin0, OUTPUT );
  pinMode(countPin1, OUTPUT );
  pinMode(countPin2, OUTPUT );
  pinMode(countPin3, OUTPUT );
  pinMode(countPin4, OUTPUT );
  counter = 0;
  Serial.begin(9600);
 
 
}
void loop ()
{
   for ( counter = 0; counter <= switchbanks ; counter ++ )  {
   if ( counter % 2 ) { count0 = HIGH; } else { count0 = LOW;   }
   if ( (counter / 2 )  % 2 ) { count1 = HIGH; } else { count1 = LOW;}
   if ( ( counter / 4 ) % 2 ) { count2 = HIGH; } else { count2 = LOW;}
   if ( (counter / 8 ) % 2 ) { count3 = HIGH; } else { count3 = LOW;}
   if ( (counter / 16 ) % 2 ) { count4 = HIGH; } else { count4 = LOW;}

 
   Serial.print ( "counter = "   );
  Serial.println ( counter );
 
    Serial.print ( "count0 = "   );
  Serial.println ( count0 );
 
  Serial.print ( "count1 = "   );
  Serial.println ( count1 );
 
  Serial.print ( "count2 = "   );
  Serial.println ( count2 );
 
    Serial.print ( "count3 = "   );
  Serial.println ( count3 );
 
    Serial.print ( "count4 = "   );
  Serial.println ( count4 );
 
  }
 
  delay ( 1000 );
 }

 
1227  Topics / Education and Teaching / Re: simple explanation of shift register use. on: April 25, 2011, 01:48:39 pm
Yes,  its probably getting away from my original " Harry Potter does Arduino" explanation for absolute beginners :-)
1228  Topics / Education and Teaching / Re: Q: Is the Arduino environment usefull for real life projects? on: April 25, 2011, 01:46:26 pm
I would never have got into micros without the soft start route of the Arduino.

I am now updating years of CMOS logic technology with 328 chips programmed with Arduino, including text LED displays, a 2 axis doming machine,  a HD LCD screen text overlay, and some electronic scoreboards, all real life applications, and I didn't have a clue 6 months ago.

So it is not the available examples and existing ideas that limit its use, its ones imagination !
1229  Topics / Education and Teaching / Re: simple explanation of shift register use. on: April 25, 2011, 01:36:02 pm
I was thinking of the MISO  MOSI  action of swapping parcels.
1230  Using Arduino / Project Guidance / Re: using function repeatedly on: April 25, 2011, 12:45:15 pm
Thats very true, at one point I actually started from scratch but when I got some hassles with that I wondered if I was heading for a dead end, so went back to what I had working in a different form.

When I get caught up and have some time, I will go back without pressure and see if it works.
Pages: 1 ... 80 81 [82] 83 84 ... 100