Show Posts
Pages: 1 2 [3] 4 5 ... 8
31  Forum 2005-2010 (read only) / Interfacing / Re: Arduino +Sparkfuns 4-digit 7-segment 16pin display on: October 10, 2010, 01:20:31 pm
Ah...
If you take a look at RefreshDisplay(), you will find two lines similar to this:
digitalWrite(digit0 + digitPosition, LOW);  // Turn off previous digit

Each digit is turned on one at a time, so the above line turn off the previously on digit, adjust the segments for the next digit, and then turn on that next digit.

You should be able to adjust the calculation of the first parameter instead of re-wiring the circuit.  Maybe something like this:
1. Change digit0 from 10 to 13
2. digitalWrite(digit0 - digitPosition, LOW);  // Turn off previous digit
3. digitalWrite(digit0 - digitPosition, HIGH);
32  Forum 2005-2010 (read only) / Interfacing / Re: Arduino +Sparkfuns 4-digit 7-segment 16pin display on: October 10, 2010, 10:23:15 am
Testato,
If I understand you correctly, it is probably simplest to adjust the wiring rather than the code.  Take a look at Arduino pins 10,11,12,13.  Those corresponds to the digits.
Say right now you have it wired like this:
ArduinoDisplay
10P
11Q
12R
13S

You have complete control as to which digit value correspond to which display digit.  What if you re-wire it like this?

ArduinoDisplay
13P
12Q
11R
10S

Good luck!
33  Forum 2005-2010 (read only) / Interfacing / Re: Arduino +Sparkfuns 4-digit 7-segment 16pin display on: March 26, 2010, 09:14:28 pm
Quote
Thank you!
The display works perfectly now!
Awesome! Glad to be able to help.

Quote
One more question: how would I go about getting the colon to stay lit all the time?
I don't know.  Sorry...   :-[
34  Forum 2005-2010 (read only) / Interfacing / Re: Arduino +Sparkfuns 4-digit 7-segment 16pin display on: March 25, 2010, 09:54:35 pm
Pinout is not the only difference.  Your display is common Cathode and my SparkFun display is common Anode.  So basically wherever the code sets pin to HIGH it needs to set it LOW and vice versa.  I only had to make 4 changes to the code and I've highlighted them [glow]yellow[/glow].  That should work.  Good luck!

Code:
/*
  WAS: Testing SparkFun's 4-digit 7-Segment Display (Blue)
  NOW: Altered for GmDude66 for H.LTC.4727
 */

int segmentA = 0; // Segments A thru P == pins 0 thru 7
int digit0 = 10; // Digits 3 thru 0 == pins 10 thru 13 (0 is LEFT most digit)

/*
[glow]Change#1 Added wiring guide for your H.LTC.4727[/glow]

W I R I N G   G U I D E

=== Common Cathode digits ===
Arduino  Display  Digit
  10        1       0 Leftmost
  11        2       1
  12        6       2
  13        8       3 Rightmost
  
=== Anode Segments ===
Arduino  Display   Segment
   0       14         A
   1       16         B
   2       13         C
   3       3          D
   4       5          E
   5       11         F
   6       15         G
*/

/*
10 digits:
 Each defines which segments should be on/off for that digit: A,B,C,D,E,F,G,P
 */
byte numbers[10] =
{
  B11000000, // 0
  B11111001, // 1
  B10100100, // 2
  B10110000, // 3
  B10011001, // 4
  B10010010, // 5
  B10000010, // 6
  B11111000, // 7
  B10000000, // 8
  B10010000  // 9
};

void setup()
{
  for (byte segment = 0; segment < 8; segment++)
    pinMode(segmentA+segment,OUTPUT);

  for (byte digit = 0; digit < 4; digit++)
    pinMode(digit0+digit,OUTPUT);
}

int perDigitTime = 100;
int digitPosition = 1;  // Start anywhere but zero so we won't crash when we try to turn off previous digit.
unsigned long previousMillis = 0;

int value = 0;
int powerOfTen[] = {
  1,10,100,1000};

void RefreshDisplay()
{
[glow]  //Change#2 (Your display is common Cathode, so to turn OFF a digit, we need to set it to +5)[/glow]
  digitalWrite(digit0 + digitPosition, [glow]HIGH[/glow]);  // Turn off previous digit

  digitPosition++;
  if (digitPosition > 3) digitPosition = 0;

  int digitValue = value % powerOfTen[ digitPosition+1 ] / powerOfTen[digitPosition];
  int number =  numbers[ digitValue ];
  
  if ((number > 0) || (value < powerOfTen[ digitPosition+1 ]))
  {
  for (byte seg = 0; seg < 8; seg++)
    digitalWrite(segmentA+seg, [glow]1 - [/glow]bitRead(number, seg) ); [glow]// Change#3 added "1-" to invert the bit for your common Cathode display[/glow]

  digitalWrite(digit0 + digitPosition, [glow]LOW[/glow]);  [glow]//Change#4 LOW will turn this digit on.[/glow]
  delay(4);
  }
}

void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > perDigitTime)
  {
    previousMillis = currentMillis;
    value++;
  }

  RefreshDisplay();
}

35  Forum 2005-2010 (read only) / Interfacing / Re: Arduino +Sparkfuns 4-digit 7-segment 16pin display on: February 23, 2010, 10:08:04 am
brtech,
Thanks for answering Jeremytsl question about the resistor.

jeremytsl,
Wow, the wiring on that clock you have on your blog is so much more compact than my breadboard. Nice...

ninjamastr,
Your code for figuring out the value of each digit is much easier to understand than my power of ten array.

I think this is part of what makes the Arduino cool.  There's a lot of sharing going on.
36  Forum 2005-2010 (read only) / Interfacing / Re: Arduino +Sparkfuns 4-digit 7-segment 16pin display on: February 21, 2010, 12:19:15 am
In case you missed it, the PINOUTS IN THE DATASHEET IS WRONG!  You can get the correct pinout from SparkFun's product page.
http://www.sparkfun.com/commerce/product_info.php?products_id=9481

I'm a n00b too and I was able to get it to work using the corrected info. As brtech said, I just wired up Arduino digital pins 0 thru 6 to drive segments A thru G (via 1K resistors), and pins 10 thru 13 to drive the digits.

Before someone yells at me, I know, I know... it is terribly wasteful to use so many Arduino pins to drive this display directly.  In "real life" one should use a 7-segment display driver.



Here are the two sketches that I saved while playing with it last week. I have since disassembled the circuit so I can't test it now.  It should work.  smiley

This one simply tests each digit in turn (no multiplexing).  I used this sketch to test that I've wired everything up correctly before I worked on trying to get them all lit up "at the same time".

Code:
/*
  Testing SparkFun's 4-digit 7-Segment Display (Blue)
 */

int segmentA = 0;
int segmentB = 1;
int segmentC = 2;
int segmentD = 3;
int segmentE = 4;
int segmentF = 5;
int segmentG = 6;
int segmentP = 7;

int digit1 = 10;
int digit2 = 11;
int digit3 = 12;
int digit4 = 13;

/*
10 digits:
 Each defines which segments should be on/off for that digit: A,B,C,D,E,F,G,P
 */
byte numbers[10] =
{
  B11000000, // 0
  B11111001, // 1
  B10100100, // 2
  B10110000, // 3
  B10011001, // 4
  B10010010, // 5
  B10000010, // 6
  B11111000, // 7
  B10000000, // 8
  B10010000  // 9
};

void setup()
{
  pinMode(segmentA,OUTPUT);
  pinMode(segmentB,OUTPUT);
  pinMode(segmentC,OUTPUT);
  pinMode(segmentD,OUTPUT);
  pinMode(segmentE,OUTPUT);
  pinMode(segmentF,OUTPUT);
  pinMode(segmentG,OUTPUT);
  pinMode(segmentP,OUTPUT);

  pinMode(digit1,OUTPUT);
  pinMode(digit2,OUTPUT);
  pinMode(digit3,OUTPUT);
  pinMode(digit4,OUTPUT);
}

void loop()
{
  for (int digitPosition=0; digitPosition < 4; digitPosition++)
  {
    digitalWrite(digit1 + digitPosition,HIGH);

    for (int numIndex=0; numIndex <= 9; numIndex++)
    {
      int number =  numbers[numIndex];
      digitalWrite(segmentA, bitRead(number, 0) );
      digitalWrite(segmentB, bitRead(number, 1) );
      digitalWrite(segmentC, bitRead(number, 2) );
      digitalWrite(segmentD, bitRead(number, 3) );
      digitalWrite(segmentE, bitRead(number, 4) );
      digitalWrite(segmentF, bitRead(number, 5) );
      digitalWrite(segmentG, bitRead(number, 6) );
      digitalWrite(segmentP, bitRead(number, 7) );
      delay(200);
    }

    digitalWrite(digit1 + digitPosition,LOW);
  }
}

I am not sure if this is the best way to multiplex a 4-digit 7-segment display, but this is what I came up with.  It displays 4 digits counting up as seen in the photo above.
Code:
/*
  Testing SparkFun's 4-digit 7-Segment Display (Blue)
 */

int segmentA = 0; // Segments A thru P == pins 0 thru 7
int digit0 = 10; // Digits 3 thru 0 == pins 10 thru 13 (0 is LEFT most digit)

/*
10 digits:
 Each defines which segments should be on/off for that digit: A,B,C,D,E,F,G,P
 */
byte numbers[10] =
{
  B11000000, // 0
  B11111001, // 1
  B10100100, // 2
  B10110000, // 3
  B10011001, // 4
  B10010010, // 5
  B10000010, // 6
  B11111000, // 7
  B10000000, // 8
  B10010000  // 9
};

void setup()
{
  for (byte segment = 0; segment < 8; segment++)
    pinMode(segmentA+segment,OUTPUT);

  for (byte digit = 0; digit < 4; digit++)
    pinMode(digit0+digit,OUTPUT);
}

int perDigitTime = 100;
int digitPosition = 1;  // Start anywhere but zero so we won't crash when we try to turn off previous digit.
unsigned long previousMillis = 0;

int value = 0;
int powerOfTen[] = {
  1,10,100,1000};

void RefreshDisplay()
{
  digitalWrite(digit0 + digitPosition, LOW);  // Turn off previous digit

  digitPosition++;
  if (digitPosition > 3) digitPosition = 0;

  int digitValue = value % powerOfTen[ digitPosition+1 ] / powerOfTen[digitPosition];
  int number =  numbers[ digitValue ];
  
  if ((number > 0) || (value < powerOfTen[ digitPosition+1 ]))
  {
  for (byte seg = 0; seg < 8; seg++)
    digitalWrite(segmentA+seg, bitRead(number, seg) );

  digitalWrite(digit0 + digitPosition, HIGH);
  delay(4);
  }
}

void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > perDigitTime)
  {
    previousMillis = currentMillis;
    value++;
  }

  RefreshDisplay();
}

I'd be happy to try to answer your questions if this is still unclear.

37  Forum 2005-2010 (read only) / Interfacing / Re: How to measure distance using radio frequency on: August 07, 2010, 02:29:44 pm
Thanks for all the responses everyone!

AWOL, differential GPS might be what I need. I will dig into that. thx!

RuggedCircuits, initially, the animals are dogs, they would wear an RF transmitter/receiver collar.  Mounting overhead camera is not an option, but side cameras on the fence would be ok.  Implanting sensors/transmitters on the perimeter is ok, but not all over the yard :-)
38  Forum 2005-2010 (read only) / Interfacing / How to measure distance using radio frequency on: August 07, 2010, 12:15:23 pm
I'd like to plot the path of several animals in an outdoor fenced area, ideally with accuracy of 12 inches or less.  

1. GPS very expensive is not accurate enough.  I don't need world-wide location, but it needs to be reasonably accurate.  
2. Ultrasonic or IR are problematic as I cannot guarantee line-of-sight.  
3. Using image processing and multiple camera is a possible solution, but that seems to be problematic when there are more than one animal in the area, and how about detection at night?!

That seems to leave RF as my only option.  Can you guys point me to hardware options that I can use to measure distance and eventually use several to triangulate the animals' location? Thank you in advance!
39  Forum 2005-2010 (read only) / Interfacing / Re: Small problem with led matrix on: March 26, 2010, 05:28:16 pm
Maybe you have found a more efficient way, but I don't see how you can combine the row and column shiftOut() in one loop.  They need to be nested don't they?

That is, enable row 0, setup columns for row 0, wait 500 ms.
disable row 0, enable row 1, setup columns for row 1, wait 500 ms, etc.

Something like this? Note that I had to use latch2 for rows to keep it independent of columns.

Code:
 for (int row=0; row < 8; row++)
  {
    digitalWrite(latch2, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, rows[row]);
    digitalWrite(latch2, HIGH);

    time = millis();
    while(time > millis() - 500)  {
      for(int i =0; i<8; i++)  {
        digitalWrite(latch1, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, greenEyes[i]);
        shiftOut(dataPin, clockPin, MSBFIRST, redOpen[i]);
        digitalWrite(latch1, HIGH);
      }
    }
  }

[edit]Of course, if you change the code to be as above, you will need to modify your circuit so the 595 for the row no longer chained to the red and green 595s.  :-([/edit]

40  Forum 2005-2010 (read only) / Interfacing / Re: Small problem with led matrix on: March 26, 2010, 05:06:42 pm
Maybe you have newer code, but in the posted code, I see shiftOuts for the columns(?), but I don't see any reference to latch2 in main loop to select which row that those column data is for.
41  Forum 2005-2010 (read only) / Interfacing / Re: control an ip camera over wifi with microcontrolle on: March 19, 2010, 12:30:54 pm
Quote
i don't care about the web interface.i need to communicate over wifi connection and no in the internet.
*If* I understood you correctly and you do not need to control the camera over the internet, using an RF link pair instead of WiFi maybe cheaper and easier.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268220866/2
42  Forum 2005-2010 (read only) / Interfacing / Re: VirtualWire, sending Integers on: March 19, 2010, 09:34:29 pm
Geeko,
I modified that code to send an array of integers.  You can modify the number of elements and assign whatever values to them.  Don't forget to change the loop bounds if you change the number of array elements.

I commented out vw_set_tx_pin(3) and vw_set_rx_pin(2) because I do not have a Mega.  I use the default Digital pin 12 for transmit, and pin 11 for receive.

I lowered speed too just to make sure it works, you're welcome to experiment and set them higher.

PS: I learned a new command while helping you: word(hi,low) combines two bytes into an integer.  A bit easier to read than bitshifts.

Good luck with your project!

Code:
// TRANSMITTER

#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder

int numbers[3]; // Change 3 to number of integers you wish to send.

void setup()
{
  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for RF Link module
  vw_setup(1000);                 // Bits per sec
  //vw_set_tx_pin(3);                // pin 3 is used as the transmit data out into the TX Link module, change this to suit your needs.

  // Initialize to some sample values
  numbers[0] = 32767;
  numbers[1] = -2;
  numbers[2] = 0;
}

void loop()
{
  vw_send( (uint8_t *)numbers, sizeof(numbers));
  vw_wait_tx();  // Wait for message to finish
  delay(1000);

  numbers[0]--;  // decrement
  numbers[1]++;  // increment
  numbers[2]++;  // increment
}


Code:
// RECEIVER

#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder

int numbers[3]; // Change 3 to number of integers you wish to send.

void setup()
{
  Serial.begin(4800);

  // Initialise the IO and ISR
  vw_set_ptt_inverted(true);    // Required for RX Link Module
  vw_setup(1000);                   // Bits per sec
  //vw_set_rx_pin(2);           // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin.
  vw_rx_start();                      // Start the receiver

  Serial.println("Receiver ready!");
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) // check to see if anything has been received
  {
    Serial.print(buflen, DEC);
    Serial.println(" bytes received!");
  
    for (int i = 0; i < buflen; i++)
    {
      Serial.print("buf[");
      Serial.print(i, DEC);
      Serial.print("]=");
      Serial.print(buf[i], DEC);
      Serial.print("  ");
    }
    Serial.println();

    //memcpy(buf, numbers, buflen);
    for (int i = 0; i < 3; i++)
    {
      numbers[i] = word(buf[i*2+1], buf[i*2]);
      Serial.print("numbers[");
      Serial.print(i, DEC);
      Serial.print("]=");
      Serial.print(numbers[i], DEC);
      Serial.print("  ");
    }
    Serial.println();
  }
  
  delay(50);
}

43  Forum 2005-2010 (read only) / Interfacing / Re: VirtualWire, sending Integers on: March 19, 2010, 01:53:33 am
I've had good luck with VirtualWire.  Tell us a bit more.  It is usually best to paste the code that you're having trouble with in your post (use the # icon in the forum editor) and tell us what error that you're getting.
44  Forum 2005-2010 (read only) / Interfacing / Re: RF Link problem on: March 14, 2010, 10:50:21 pm
My thoughts:

1. Have you tried NOT calling vw_set_ptt_inverted()?
I have used that RF pair successfully and I did not call vw_set_ptt_inverted() on either my transmitter nor on my receiver.

2. Have you tried NOT calling vw_set_tx_pin() on the transmitter and using the default pin 12?  I don't have a Mega, but I believe PWM (needed by VirtualWire) is only supported on pins 0 thru 13.

See PWM under Input and Output on this page:
http://arduino.cc/en/Main/ArduinoBoardMega


45  Forum 2005-2010 (read only) / Interfacing / Re: necessary to get usb shield? on: March 13, 2010, 12:59:30 am
cr0sh,
I believe gobetweno is what you had in mind.
http://www.mikmo.dk/gobetwino.html

novum,
I have not played with gobetweno, but it looks like a good option. It's free and requires no extra hardware.

Pages: 1 2 [3] 4 5 ... 8