Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Simulating respiration with Arduino? on: May 24, 2011, 02:32:37 pm
I would think a bladder enclosed in a semi-articuled shell would be a good place to start.  Add an air piston connected to the bladder on one side, free to ATM on the other.  The piston controlled by a linear actuator.  The code would only have to modulate the movement of the actuator.

I'm sure there are other methods.  This was the first idea that popped into my head.

Please post updates! Sounds interesting.
2  Using Arduino / Project Guidance / Re: optical flow sensor for mobile robot navigation on: May 18, 2011, 12:41:12 pm
I came across the following while doing some research.  It wasn't relevant, but I read the entire thing because it was so fascinating.  I think it will help you:

http://www.societyofrobots.com/programming_computer_vision_tutorial.shtml

There's a lot on that web site, so get comfy and enjoy!
3  Using Arduino / Project Guidance / Re: Clock selector on: May 02, 2011, 12:01:58 pm
I used the suggestion from the other thread to send
wire.send(0)
to all 4 digits and it worked like a charm.

In preparation for soldering up the project I wanted to make sure the clock will work when it's slowed down to increment once per minute, rather than once per second as coded:

nextTime = currentTime + 1000; // wait another 1000ms

I changed that to + 60000, thinking that would be the only thing necessary.  What I thought would be a simple change has consequences I wasn't expecting. 

When the switch position is changed, it takes a minute for the display to come on.  I'm not sure why.  I thought the display would still read the value of the switch position, check the cases, and display accordingly.  But it doesn't. 

What am I missing?

relevant segment of code repasted from complete code in earlier post:

Quote
  unsigned long currentTime = millis();
  // if 1000 milliseconds have passed
  
  //if the binary value of switchPos is odd, then time may increment
  if (isRunning) {
    
  if (currentTime >= nextTime) {
    // increment time
    timeCounter++; // add one second to the time
    nextTime = currentTime + 60000; // wait another 1 minute
  
    // display current time
    int thousands, hundreds, tens, base;
  
    // split into digits
    thousands = timeCounter / 1000;
    hundreds = (timeCounter % 1000) / 100;
    tens = (timeCounter % 100) / 10;
    base = (timeCounter % 10);

    Wire.beginTransmission(0x38);
    Wire.send(1);
    Wire.send(lookup[base]);
    Wire.send(lookup[tens]);
    Wire.send(lookup[hundreds]);
    Wire.send(lookup[thousands]);
    Wire.endTransmission();
    
  }
 } 



4  Using Arduino / Project Guidance / Re: Clock selector on: May 01, 2011, 04:26:16 pm
Thanks, Bilbo.  I replied in the other thread smiley-razz

I'm aware of the hour rollover issue.  Luckily for me the scenes of the play are short enough that it shouldn't be an issue. And if it becomes an issue, I will work on it at that point.

For now, my priorities have to be soldering up the project and then installing it.  I also forgot that I need to put in some status LEDs so the operator can see what state the display is in.  Then get over to the warehouse by 4 to load a truck, and so on.
5  Using Arduino / Programming Questions / Re: wire, i2p, 4x7segment LED on: May 01, 2011, 04:18:08 pm
I'll try routing the ground tomorrow first thing. I tried that with the +5v leg, and just assumed the ground would work the same.

But let's assume that doesn't work.... how would I turn off the segments?  I can't find any list of commands beyond the few that are mentioned on the arduino wire library reference page.
6  Using Arduino / Project Guidance / Re: Clock selector on: May 01, 2011, 02:44:44 pm
UPDATE:

I successfully incorporated the odd / even condition to determine if the counter increments or not, depending on the modulus of the switchPosition.  In order to do that, I had to jigger around some of my wiring arrangements and pin assignments, as the code below shows.

Due to the physical layout of the switch and the bridges between the legs inside, I had to reassign the INPUT pins.  I also had to switch the order that the swtichPos value was constructed.  But I'm pleased that I got it right on the first try.

Now there are only two things left to do before my project is complete:
1. Figure out how to send a wire.h command that turns the display off in the default case.  I've tried sending various 0's and such, but to no effect. 
2. Solder it all up onto a project board and install back in the appliance.  If I can't do a command that shuts off the display, I'll have to make a physical shutter that passes between the appliance window and the display.  I really don't want to have to do that, but at least it's a back up solution.

Code:
Quote


#include <Wire.h>

// pins for the switch
// Don't use pin 1 - it's for serial.
// the pins are read in an order such that the switch_pin will have an odd value for my action cases
uint8_t switch_pin[4] = {2, 3, 4, 5};

uint8_t p_switchPos;

bool isRunning;

unsigned long nextTime, timeCounter;

const int lookup[10] = {0x3F,0x06,0x5B,0x4F,0x66,
                        0x6D,0x7D,0x07,0x7F,0x6F};

void setup() {
  // begin serial at 115.2kbaud
  Serial.begin(9600);
  
  // initialize the inputs
  /*for (uint8_t i = 0; i < 4; i++) {
   pinMode(switch_pin, INPUT);
  }  
  */
  for (uint8_t i = 2; i < 6; i++) {
    pinMode(switch_pin, INPUT);
  }

  // initialize I2C
  Wire.begin();

  // reset the time counter
  timeCounter = 0;
  
  // reset timer
  nextTime = millis();
  
  // reset the switch position
  p_switchPos = 16; // set it to something impossible to get
  
  // not sure what this does, but it's in the original.
  Wire.beginTransmission(0x38);
  Wire.send(0);
  Wire.send(B01000111);
  Wire.endTransmission();
}

void loop() {
  // read the switch
  uint8_t switchPos; // switchpos will have a value between 0 and 15.
  for (uint8_t i = 0; i < 4; i++) {
    switchPos |= digitalRead(switch_pin) << i;
  }
  
  //check to see if the binary value of switchPos is odd. 
  isRunning = switchPos % 2 == 1;
  
  // if switch position has changed
  if (switchPos != p_switchPos) {
    switch(switchPos) {
    // case 1100 from original code
    case 3:
      // set starting time to 900
      timeCounter = 900;
      break;
    // case 1010, from original code
    case 5:
      // set starting time to 730
      timeCounter = 730;
      break;
    // case 1110, from original code
    case 7:
      // set starting time to 845
      timeCounter = 845;
      break;
    // case 1001 from original code
    case 9:
      // set starting time to 930
      timeCounter = 930;
      break;
    // case 1101 from original code
    case 11:
      // set starting time to 845
      timeCounter = 1130;
      break;
    // if it's not any of the above cases
    default:
      // set starting time to 0
      timeCounter = 0;
      break;
    }
  
    // set previous pos to current pos
    p_switchPos = switchPos;
  }
  
  unsigned long currentTime = millis();
  // if 1000 milliseconds have passed
  
  //if the binary value of switchPos is odd, then time may increment
  if (isRunning) {
    
  if (currentTime >= nextTime) {
    // increment time
    timeCounter++; // add one second to the time
    nextTime = currentTime + 1000; // wait another 1000ms
  
    // display current time
    int thousands, hundreds, tens, base;
  
    // split into digits
    thousands = timeCounter / 1000;
    hundreds = (timeCounter % 1000) / 100;
    tens = (timeCounter % 100) / 10;
    base = (timeCounter % 10);

    Wire.beginTransmission(0x38);
    Wire.send(1);
    Wire.send(lookup[base]);
    Wire.send(lookup[tens]);
    Wire.send(lookup[hundreds]);
    Wire.send(lookup[thousands]);
    Wire.endTransmission();
  }
 }
}


7  Using Arduino / Programming Questions / wire, i2p, 4x7segment LED on: May 01, 2011, 02:25:18 pm
Hi,

I'm using a 4x7segment LED display from Gravitech:
http://www.gravitech.us/i2c47di.html

I need the display to be ON for certain states, and OFF for others.  When it's off there should be no power to the LEDs. 

I've been hunting all over the place, but I can't find any documentation that explains how to send that sort of a command to the I2c bus.  I also tried power the display using a digital out pin, and setting that pin to LOW during certain cases.  But then the display didn't light when it should have, either.

Any ideas?
8  Using Arduino / Project Guidance / Re: Clock selector on: May 01, 2011, 10:45:57 am
That was a very clear explanation.  I understand, now, how your commands assigned a numerical value for the switchPosition.

Thanks again for taking the time to explain some of this.

Quote
I take advantage of the fact that digitalRead returns a boolean value, that is, a value that is either 0 or 1.
I had considered trying to use a boolean form, but the reference section on Boolean lead me to believe that it returned the word 'false' or 'true'.  I didn't know that 0 and 1 were interchangeable with the words.  It makes sense now, of course.

This is very useful stuff - I can easily imagine referring back to it in the future smiley

9  Using Arduino / Project Guidance / Re: Clock selector on: April 30, 2011, 04:40:32 pm
Quick reply in gratitude for a quick response!

This code compiled at just over half the byte-size of mine (show-off!), and it works much better smiley

The display starts counting from the proper number at each of the switch positions I needed.  There are a couple things it doesn't do, (for instance the clock starts ticking as soon as the power is on, and continues in between switch positions whereas I need it to be Off on the even positions and On in the odd ones). I'm going to try to work that in.

But first, of course, I'm going to have to understand how you did what you did.  I'm still so new to this I just don't get a lot of it.

For what it's worth I did improve my sketch after my last post.  I mapped some different integer values to the input states, such as pin4 (0,1,0,4) so that different switch positions yielded different integer values.  In this way I could assign cases better.  I only discovered this flaw after asking the serial monitor to print the value of my switchState variable.  The only value being returned under all positions was 0.  I fixed that part, and was very pleased with myself!

Thanks again for taking a look at this.

How does this line work?
Quote
  uint8_t switchPos; // switchpos will have a value between 0 and 15.
  for (uint8_t i = 0; i < 4; i++) {
    switchPos |= digitalRead(switch_pin) << i;
  }


I mean, how is does the program combine the values of the pins into a value between 0 and 15?  In my code I explicitly assigned a range through the mapping, but I don't see that here.

10  Using Arduino / Project Guidance / Re: Clock selector on: April 30, 2011, 02:36:17 pm
OK, I'm kind of stuck.

I'm able to read the state of the switch (determine which pins are active) and output that to the serial monitor.  And I've written up the different cases for what to do in each pin configuration.

I also have the display working properly, at least, it's counting up just fine.  I can also start it at whatever arbitrary time I choose by changing a value in the sketch. 

But I haven't been able to join the two parts.  When I run the following code, the serial monitor returns values for the pin states.  So I know that's fine.  But the display doesn't ever light up.  Also, if I run the Gravitech example sketch for the display, which simply counts from 0 to 9999 and then rolls over, the display will hang on whatever number is on the screen when I start to upload my hybrid sketch.  I can run through all of the switch positions without a change in the display even though the serial monitor is returning changes in the pin states.

Here's where I think I'm failing:
-First of all I think the whole loop needs to be structured differently. 
-Right now it's always checking the state of the input pins, so there's no way for it to get out of that loop. -I think the display should be counting all the time, which I don't think would happen here.
-I also can't figure out how to tell the display to STOP displaying outside of the cases that I've defined.  Of course, for that matter I haven't figured out how to START it displaying either...

I'm not trying to reinvent the wheel, which is why I'm relying on pasting in code that already works.  It seems that I'm missing something obvious structurally, but I'm simply out of my element here.
Code:
#include <Wire.h>
int oldState(0); //sets a variable to store the previous switch state

void setup() {
  Serial.begin(9600);
  pinMode(1, INPUT);  //these are the pins that correspond to the pins on the switch
  pinMode(2, INPUT);
  pinMode(4, INPUT);
  pinMode(8, INPUT);
  Wire.begin();        // join i2c bus (address optional for master)
  delay(500);
  }

void loop() {
 
/************** First we read the state of the switch's legs ************/

 
  int sensorValue1 = digitalRead(1); // read the first pin
  Serial.print("Pin 1: ");           
  Serial.println(sensorValue1, DEC);  // print the value (0 or 1) on the serial monitor
  int range1 = (sensorValue1, 0, 1);
 
  int sensorValue2 = digitalRead(2);
  Serial.print("Pin 2: ");
  Serial.println(sensorValue2, DEC);
  int range2 = (sensorValue2, 0, 1);
 
  int sensorValue4 = digitalRead(4);
  Serial.print("Pin 4: ");
  Serial.println(sensorValue4, DEC);
  int range4 = (sensorValue4, 0, 1);
 
  int sensorValue8 = digitalRead(8);
  Serial.print("Pin 8: ");
  Serial.println(sensorValue8, DEC);
  int range8 = (sensorValue8, 0, 1);
 
  Serial.println();  //print the state (eg 1011) to the serial monitor

int switchState = (sensorValue1, sensorValue2, sensorValue4, sensorValue8);  //set a variable to record the current switch state
 
if (switchState != oldState) {  //compare the old value to the current one

  /*-----> code copied from Gravitech Example, confirmed to work in that sketch ----->*/ 
  const int lookup[10] = {0x3F,0x06,0x5B,0x4F,0x66,
                          0x6D,0x7D,0x07,0x7F,0x6F};
  int Count, Thousands, Hundreds, Tens, Base;
 
  Wire.beginTransmission(0x38);
  Wire.send(0);
  Wire.send(B01000111);
  Wire.endTransmission();
  /*------> end of copy ------>*/
 
switch (switchState) {
   
    case 1100:    //if leg1 and leg2 are on, then start counting at 900, and then add 1 digit per second
       
       /*----> code copied from Gravitech, confirmed to work outside of switch cases ---->*/
       for (Count=900;Count<=9999;Count++)
      {
      Wire.beginTransmission(0x38);
      Wire.send(1);
      Thousands = Count/1000;
      Hundreds = (Count-(Thousands*1000))/100;
      Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
      Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
      Wire.send(lookup[Base]);
      Wire.send(lookup[Tens]);
      Wire.send(lookup[Hundreds]);
      Wire.send(lookup[Thousands]);
      Wire.endTransmission();
      delay(1000);
      }
      /*------> end copy ----->*/
    break;
 
   case 1010:     //if legs 1 and 4 are on, then start counting at 730 and add 1 per second.
     for (Count=730;Count<=9999;Count++)
    {
     Wire.beginTransmission(0x38);
     Wire.send(1);
     Thousands = Count/1000;
     Hundreds = (Count-(Thousands*1000))/100;
     Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
     Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
     Wire.send(lookup[Base]);
     Wire.send(lookup[Tens]);
     Wire.send(lookup[Hundreds]);
     Wire.send(lookup[Thousands]);
     Wire.endTransmission();
     delay(1000);
    }
    break;
 
   case 1110:   //if legs 1, 2, and 4 are on, start counting at 845 and add 1 per second
     for (Count=845;Count<=9999;Count++)
    {
     Wire.beginTransmission(0x38);
     Wire.send(1);
     Thousands = Count/1000;
     Hundreds = (Count-(Thousands*1000))/100;
     Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
     Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
     Wire.send(lookup[Base]);
     Wire.send(lookup[Tens]);
     Wire.send(lookup[Hundreds]);
     Wire.send(lookup[Thousands]);
     Wire.endTransmission();
     delay(1000);
    }
    break;
 
  case 1001:  //legs 1 and 8 are on start counting at 930 and add 1 per second
    for (Count=930;Count<=9999;Count++)
    {
    Wire.beginTransmission(0x38);
    Wire.send(1);
    Thousands = Count/1000;
    Hundreds = (Count-(Thousands*1000))/100;
    Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
    Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
    Wire.send(lookup[Base]);
    Wire.send(lookup[Tens]);
    Wire.send(lookup[Hundreds]);
    Wire.send(lookup[Thousands]);
    Wire.endTransmission();
    delay(1000);
    }
    break;
 
  case 1101:  //if legs 1, 2, and 8 are on start counting at 1130 and add 1 per second
    for (Count=1130;Count<=9999;Count++)
    {
    Wire.beginTransmission(0x38);
    Wire.send(1);
    Thousands = Count/1000;
    Hundreds = (Count-(Thousands*1000))/100;
    Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
    Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
    Wire.send(lookup[Base]);
    Wire.send(lookup[Tens]);
    Wire.send(lookup[Hundreds]);
    Wire.send(lookup[Thousands]);
    Wire.endTransmission();
    delay(1000);
    }
    break;
 delay (50); //debounce the switch

  }
  oldState = switchState;  //store the current value of the switch for the next time through the loop
  }
 delay (2000); // wait 2 seconds before heading back the start to take a new switch reading
}
11  Using Arduino / Displays / Re: 7-Segment Shield on Arduino UNO? on: April 29, 2011, 09:12:20 am
UPDATE:
I have exchanged several emails with Tony at Gravitech support.  My problem was solved by replacing the wire contacts that I had crimped into the through-holes with soldered leads.  It's working perfectly now.

I don't think that would resolve the issue with the shield, though.
12  Using Arduino / Project Guidance / Re: Clock selector on: April 29, 2011, 09:09:27 am
Thanks for the pointers!

I'm glad to hear that it's not only doable, but that the RTC isn't necessary.  I was thinking it would simply sending the proper code to display the next number, not so much for accurate timing.  But simpler is better, both in hardware and in software.

Yes, this is for a stage performance.  In the past we've always done this the easy way: a couple of alarm clocks that a technician sets at the top of the show.  It's easy to screw up and very clumsy.  I've realized the need to learn more about electronics and control, and luckily I've had a couple of weeks to devote to this.

I'll post back as the project progresses (or stumbles).  My goal is to have it working on Monday, since actors are onstage on Wednesday.  Ugh.
13  Using Arduino / Project Guidance / Clock selector on: April 28, 2011, 03:46:39 pm
Hi All,

I know this is an extremely ambitious first project for a code newbie, but I'm kind of stuck having to do this for work.  Not really by choice.

I have to replace the digital clock in an appliance with a larger one, and the time needs to be changed at the start of each scene to reflect the fact that time has passed since the end of the last scene.  So here's how I'm trying to implement it:

A 16 position rotary selector switch
A 4 digit 7 segment LED display
a RTC module

The Arduino will read the position of the selector switch and send the corresponding signal to the display:
Position 0 = off
 1 Time = 9:00
 2 off
 3 Time = 7:30
 4 off
 5 Time = 8:00
 6 off
 7 Time = 9:45
 8 off
 9 Time = 11:45

The Arduino will have to read the state of the switch.  If it's at a position that requires a time to be displayed, the start time will be established and sent to the display, then the RTC takes over and bumps the digits as time passes. 

I know I'm going to be using the Wire library, and there will be several if...else clauses.  I've started going through the info on the RTC and the display in order to understand if I'll have to convert between decimal, bcd, 0x, etc.  It's pretty daunting stuff if you've never seen it before.

Am I missing anything else obvious? 

As I mentioned above, this is my first project ever, and my first experience dealing with the software side, too.  So please be constructive in the criticism smiley
14  Using Arduino / Displays / Re: 7-Segment Shield on Arduino UNO? on: April 28, 2011, 02:23:44 pm
Was this problem ever resolved?

I ask because I'm having a similar problem with a very similar item:
http://www.gravitech.us/i2c47di.html

This appears to be the I2C 7segment display that's used on the temp. shield.

My display doesn't light up either.  Power led on the board lights up, and I get light from an LED when jumped off of A4 or A5 (LED appears dim, so I think it's flickering really fast).

Here's the example code they offer to test it:
Quote
/**********************************************************
Example program I2C-7SEG interface with Arduino.

SETUP:    I2C-7SEG => Arduino
          PIN1 => +5V PIN2 => GND, PIN3 => A4, PIN4 => A5
Note:     The program is written for address 0x70 (Arduino address 0x38).
          This program was tested using Arduino Nano
Document: SAA1064 datasheet
Updated:  July 30, 2008
E-mail:   support@gravitech.us
          Gravitech
(C) Copyright 2008 All Rights Reserved
**********************************************************/

#include <Wire.h>
 
void setup()

  Wire.begin();        // join i2c bus (address optional for master)
  delay(500);

 
void loop()

  const int lookup[10] = {0x3F,0x06,0x5B,0x4F,0x66,
                          0x6D,0x7D,0x07,0x7F,0x6F};
  int Count, Thousands, Hundreds, Tens, Base;
  
  Wire.beginTransmission(0x38);
  Wire.send(0);
  Wire.send(B01000111);
  Wire.endTransmission();
  
  for (Count=0;Count<=9999;Count++)
  {
    Wire.beginTransmission(0x38);
    Wire.send(1);
    Thousands = Count/1000;
    Hundreds = (Count-(Thousands*1000))/100;
    Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
    Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
    Wire.send(lookup[Base]);
    Wire.send(lookup[Tens]);
    Wire.send(lookup[Hundreds]);
    Wire.send(lookup[Thousands]);
    Wire.endTransmission();
    delay(10);
  }



Like the original poster, I'm also very new to all of this.  So if there's something fishy in the code I'm not going to notice it.   I'm also waiting to hear back from Gravitech support.

Any advice will be greatly appreciated!
Pages: [1]