Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Beat Bearing Code Error on: March 22, 2009, 09:57:54 pm
I hate Vista.  The code runs fine on my XP machine.  I have the board selected as Decimilia on both machines.  Mem, is the clock still ticking?
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Beat Bearing Code Error on: March 21, 2009, 07:32:52 pm
MDC BBB??  What does this mean?  Forgive my ignorance.  BTW I am using a 168 chip on a decimilia board
3  Forum 2005-2010 (read only) / Syntax & Programs / Beat Bearing Code Error on: March 19, 2009, 07:43:22 pm
I am getting the following error

Quote
Quote
Binary sketch size: 3124 bytes (of a 14336 byte maximum)


avrdude: stk500_loadaddr(): (a) protocol error, expect=0x14, resp=0xfe

avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0xe6
avrdude: stk500_cmd(): programmer is out of sync

I can load and run the Blink LED sketch just fine.  The code compiles fine.  Is this just not running because I don't have things all hooked up yet and the board is expecting to read some values from multiplexer chips? http://www.make-digital.com/make/vol17/?pg=128 Here's the project  Anyone see any other issues?  Here's the code

Quote
/*
 * Beatbearing firmware
 *
 * Peter Bennett
 * pete@petecube.com
 *
 * NOTE:
 * this isn't the most efficiently coded program, but is the one that I was using as a prototype
 * when writing up the BeatBearing article
 *
 * Keep an eye on www.beatbearing.co.uk for suggested updates to this firware,
 * including a version with proper debouncing and use of the digital pins for input.
 *
 * Make sure to choose correct board and serial port before programming
 *
 * This was written in Arduino v12
 */

int A0_1 = 2;                   // declare output pins
int A1_1 = 3;
int A2_1 = 4;
int A3_1 = 5;
int A0_2 = 6;
int A1_2 = 7;
int A2_2 = 8;
int A3_2 = 9;

int Z_1 = 0;                      // declare input pins
int Z_2 = 1;

int thresholdLow = 3000;
int thresholdHigh = 7000;

int stateMatrix[32][8] = {        // stores all of the values.
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0};          

int averages[32] = {        // stores all of the values.
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0};          


boolean bState[32] = {
  B0, B0, B0, B0, B0, B0, B0, B0,
  B0, B0, B0, B0, B0, B0, B0, B0,
  B0, B0, B0, B0, B0, B0, B0, B0,
  B0, B0, B0, B0, B0, B0, B0, B0};


void setup() {

  Serial.begin(9600);

  pinMode(A0_1, OUTPUT);                    // set outputs      
  pinMode(A1_1, OUTPUT);
  pinMode(A2_1, OUTPUT);
  pinMode(A3_1, OUTPUT);

  pinMode(A0_2, OUTPUT);      
  pinMode(A1_2, OUTPUT);
  pinMode(A2_2, OUTPUT);
  pinMode(A3_2, OUTPUT);
}

void loop(){

  byte byteOut1 = B00000000;
  byte byteOut2 = B00000000;
  byte byteOut3 = B00000000;
  byte byteOut4 = B00000000;
  byte byteOut5 = B00000000;
  byte stopByte = B11111111;


  for (int a = 0; a < 32; a++) {                                // first shift all old values up
    for (int b = 7; b > 0; b--) {
      stateMatrix[a] = stateMatrix[a][b-1];
    }
  }


  for (long count = 0; count < 16; count++) {                  // now get all the states 0-1024

    digitalWrite(A0_1, (count >> 3) & 1);
    digitalWrite(A1_1, (count >> 2) & 1);
    digitalWrite(A2_1, (count >> 1) & 1);
    digitalWrite(A3_1, (count >> 0) & 1);

    digitalWrite(A0_2, (count >> 3) & 1);
    digitalWrite(A1_2, (count >> 2) & 1);
    digitalWrite(A2_2, (count >> 1) & 1);
    digitalWrite(A3_2, (count >> 0) & 1);

    stateMatrix[count][0] = analogRead(Z_1);                      // and insert new values at position 0
    stateMatrix[count + 16][0] = analogRead(Z_2);
  }


  for (int a = 0; a < 32; a++) {                                // now calculate averages
    averages[a] = 0;
    for (int b = 0; b < 8; b++) {
      averages[a] += stateMatrix[a];
    }
  }


  // determine binary state using thresholds
  for (int n = 0; n < 32; n++) {
    if ((bState[n] == B0) && (averages[n] < (thresholdLow))) {                           // last sure value was 0 AND below low threshold
      bState[n] = B1;                                                                             // then set to 1;
    }
    else if ((bState[n] == B1) && (averages[n] > (thresholdHigh))){                      // last sure value was 1 AND over high threshold
      bState[n] = B0;                                                                             // set to 0;
    }
  }


  // now assemble the output bytes

  int stateCount = 0;

  // first byte
  for (int n = 0; n < 7; n++) {
    if (bState[stateCount] == B1) {
      byteOut1 |= (1 << n);                // then set to 1;
    }
    else {
      byteOut1 &= ~(1 << n);              // set to 0;
    }
    stateCount++;
  }

  // second byte
  for (int n = 0; n < 7; n++) {
    if (bState[stateCount] == B1) {
      byteOut2 |= (1 << n);                // then set to 1;
    }
    else {
      byteOut2 &= ~(1 << n);              // set to 0;
    }
    stateCount++;
  }

  // third byte
  for (int n = 0; n < 7; n++) {
    if (bState[stateCount] == B1) {
      byteOut3 |= (1 << n);                // then set to 1;
    }
    else {
      byteOut3 &= ~(1 << n);              // set to 0;
    }
    stateCount++;
  }

  // fourth byte
  for (int n = 0; n < 7; n++) {
    if (bState[stateCount] == B1) {
      byteOut4 |= (1 << n);                // then set to 1;
    }
    else {
      byteOut4 &= ~(1 << n);              // set to 0;
    }
    stateCount++;
  }

  // fifth byte (shorter than others)
  for (int n = 0; n < 4; n++) {
    if (bState[stateCount] == B1) {
      byteOut5 |= (1 << n);                // then set to 1;
    }
    else {
      byteOut5 &= ~(1 << n);              // set to 0;
    }
    stateCount++;
  }

  // send the values over serial to Processing
  Serial.print(byteOut1, BYTE);
  Serial.print(byteOut2, BYTE);
  Serial.print(byteOut3, BYTE);
  Serial.print(byteOut4, BYTE);
  Serial.print(byteOut5, BYTE);
  Serial.print(stopByte, BYTE);
}
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Clock driver- Prize to you for a fix! on: July 08, 2008, 01:20:43 pm
I burn my own bootloaders and selected to use the external 16MHz clock when setting the chip up.  Does this wiring.c override those settings?  Do I need an external crystal with the 168 chip?  (Yes, the external crystal is probably more accurate)
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Clock driver- Prize to you for a fix! on: July 08, 2008, 01:13:59 pm
Thanks!  I actually sent you a PM with additional info.  and a pic.  I'll give it a try.
6  Forum 2005-2010 (read only) / Syntax & Programs / Clock driver- Prize to you for a fix! on: July 08, 2008, 12:26:55 pm
I have built a slave clock driver- a device to send a 24 pulse to a slave clock (one of those old institutional clocks that we all saw in school run by a maste clock in the office).  I cannot get it to keep accurate time!! (off 1 min. 22 sec. in 12 hours)  I have read about the counter timeout at 9 hours and 32 minutes.  I tried using the millis rollover function to compensate for this, but I'm afraid I just am not that good at this- I'm just a beginner.  Here's what I have.  The clock should be n for 2s and off for 58s.  This seems to me to be a very simple request of the Arduino.  I am really frustrated that I/it cannot accomplish it.  [glow]To whoever sends me a working fix, I'll send you a free old skool clock![/glow]

/* Millis Rollover
 *
 * Example of counting how many times the millis() function has rolled over
 *  by Rob Faludi http://www.faludi.com
 *
 * for the ATMEGA168 with Arduino 0010 the max value is 34359737 or about 9 hours and 32 mintues
 * for more information see: http://www.arduino.cc/en/Reference/Millis
 *
 */

#define ledPin 13 // light for status output


void setup() {
  Serial.begin(9600); // start serial output
    digitalWrite(ledPin, HIGH);   // startup blink
    delay(250);                     // waits
    digitalWrite(ledPin, LOW);    // sets the LED off
    delay(250); // startup blink
    digitalWrite(ledPin, HIGH);   // startup blink
    delay(250);                     // waits
    digitalWrite(ledPin, LOW);    // sets the LED off
    delay(1000);          // wait
}


void loop() {
  int rollovers = millisRollover(); // get the number of rollovers so far

  Serial.print("Rollovers: "); // show the number of rollovers so far
  Serial.println(rollovers,DEC); //
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(2000);                     // waits
    digitalWrite(ledPin, LOW);    // sets the LED off
    delay(58000); // waits
  
}


int millisRollover() {
  // get the current millis() value for how long the microcontroller has been running
  //
  // To avoid any possiblity of missing the rollover, we use a boolean toggle that gets flipped
  //   off any time during the first half of the total millis period and
  //   then on during the second half of the total millis period.
  // This would work even if the function were only run once every 4.5 hours, though typically,
  //   the function should be called as frequently as possible to capture the actual moment of rollover.
  // The rollover counter is good for over 35 years of runtime. --Rob Faludi http://rob.faludi.com
  //
  static int numRollovers=0; // variable that permanently holds the number of rollovers since startup
  static boolean readyToRoll = false; // tracks whether we've made it halfway to rollover
  unsigned long now = millis(); // the time right now
  unsigned long halfwayMillis = 17179868; // this is halfway to the max millis value (17179868)

  if (now > halfwayMillis) { // as long as the value is greater than halfway to the max
    readyToRoll = true; // you are ready to roll over
  }

  if (readyToRoll == true && now < halfwayMillis) {
    // if we've previously made it to halfway
    // and the current millis() value is now _less_ than the halfway mark
    // then we have rolled over
    numRollovers = numRollovers++; // add one to the count the number of rollovers
    readyToRoll = false; // we're no longer past halfway
  }
  return numRollovers;
}
7  Forum 2005-2010 (read only) / Interfacing / Interface with slave clock on: May 21, 2008, 08:36:32 pm
I am planning on making a master clock to run one of those old school clocks that ran off a 24VDC signal that was sent 1x a minute by a master clock.  The clock mechanism draws about 200mA of current.  I know that the chip is picky with its supply voltage so I'm wondering how much I need to "segregate" their power supplies or how best to do so.  I was going to use a variation on the Arduino LED "hello world" program.  I can use either a transistor to drive the clock or a relay.  Opinions.  The clock will be plugged in to AC line voltage in the USA.   Thanks!
Here's some info on the clocks.
http://setclocks.zayre-electronics.com/
8  Forum 2005-2010 (read only) / Exhibition / Re: Growduino smart garden on: July 22, 2008, 09:50:18 pm
Part of your timing problems could be caused by the millis rollover at 9 hrs 32 min?  After this time, the internal timer goes back to zero.  Consider possibly two sensor inputs, temp via a thermistor and humidity via a humidity sensor.  Construct a grid with various humidity and temperature combinations and watering durations.  You will have to run some experiments with a scale/balance and estimate how much water the pots lose at certain temp/humidity combinations.  The Arduino consults this grid and then chooses the correct interval of time to run the pump.  Another option is to measure soil moisture.  This would make your life easier
http://emesystems.com/pdfs/SMX.pdf

http://www.hobby-boards.com/catalog/product_info.php?language=en&products_id=1547
9  Forum 2005-2010 (read only) / Exhibition / Old Skool Clock Driver on: July 22, 2008, 10:11:56 pm
I built a driver to send a 2 second 24V pulse to a slave clock once a minute to run the mechanism.  Pretty simple, but it works smiley  some help from mem on the millis timeout.  It's just the standard Arduino standalone without serial communication + a transistor and a DC-DC converter with regulated output.  The link is a blow-up of the board.
http://www.geocities.com/mycoleptodiscus/Picture1.jpg

Pages: [1]