Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: How to read values greater than 255? on: September 18, 2013, 07:14:17 pm
These examples are not tested.

Code:
// request two bytes, and make an integer with them. Expect low byte first.

Wire.requestFrom(_address, 2); //requests that the slave sends the pin status back
if( Wire.available() == 2){           // we expect 2 bytes
  byte low = Wire.read();            // read a byte of the buffer
  byte high = Wire.read();           // read the next byte of the buffer.
  int result = word (high, low);    // melt them into an integer
}
else {
  Serial.println("Error, not received two bytes);
}


http://arduino.cc/en/Reference/WordCast

The requestEvent may contain only one 'Wire.write' function call. There are improvements made to allow more calls, but I don't know if the current library has them. That's why I create a buffer to send them all at once with a single 'Wire.write' call.

Code:
void requestEvent() {
  int value = analogRead(_analogpinnumber); //reads analog analog pin
 
  // create a buffer. This buffer can be used to send more than only 2 bytes.
  byte buffer[10];
  buffer[0] = lowByte (value);
  buffer[1] = highByte ( value);
  Wire.write( buffer, 2);
}

http://arduino.cc/en/Reference/LowByte
http://arduino.cc/en/Reference/HighByte
http://arduino.cc/en/Reference/WireWrite

That worked.  Thank you so much!  Cool thing to know!
2  Using Arduino / Programming Questions / Re: How to read values greater than 255? on: September 18, 2013, 08:50:30 am
Show us what you have (sketch between code tags please, use the '#'-button).
You can transmit two bytes in the Slave, and request two bytes in the Master.


I am using a library, but here is basically what I have
master
Code:
void setup{
        Wire.beginTransmission(_address); //begins transmission to the slave with specified address
        Wire.write(analog pin #);
        Wire.endTransmission(); //ends transmission
        Wire.requestFrom(_address,(byte)2); //requests that the slave sends the pin status back
        while(Wire.available()){ //it reads
            _a = Wire.read(); //sets to a
            return (map(_a, 0, 255, 0, 1023)); //returns 0-255 value mapped to the original 0-1023 value
        }
    }
slave
Code:
void receiveEvent(int){
    if (Wire.available()) //if there is something in the buffer
    {
         _analogpinnumber = Wire.read(); //reads the buffer as an interger
    }

void requestEvent(){
        int value = analogRead(_analogpinnumber); //reads analog analog pin
        Wire.write(map(value, 0, 1023, 0, 255)); //sends the value to the master mapped for 0-255 because that is all that can fit in one byte
    }

I wish to send the number with the full resolution, unmapped.
3  Using Arduino / Programming Questions / Re: How to read values greater than 255? on: September 17, 2013, 02:33:13 pm
Code:
int x;
Wire.write( highByte( x));
Wire.write( lowByte( x));

http://arduino.cc/en/Reference/HighByte
http://arduino.cc/en/Reference/LowByte

Do you use "Wire.onReceive()" in the slave ?

Hi I am trying to do something similar.  I am writing a value of 0-1023 from the slave (analog pin value) to the master.  Right now I am just mapping it from 0-255 but I lose 3/4 of my resolution.  How do you read it from the master?  I guess I don't know how to implement it correctly.
Thanks,
Chris
4  Development / Other Hardware Development / Re: Problem with LT1639 Op-Amp on: June 05, 2013, 01:54:07 pm
I emailed LT and this is the response I got

Quote
Are you using a single 24V supply, or +/-12V?  If single supply, then you are probably running into an output swing issue.  On page 4 of the data sheet, the typical output short circuit current is listed as 20mA on a 5V supply.  The Output Saturation Voltage vs Load Current (Output High) graph on page 8 shows the output saturation voltage approaching 1V at 10mA output current so I would not be surprised to see it at 1.3V when the output is shorted and driving 20+mA with a 24V supply.  Can you use a negative rail to allow more headroom and provide a load to limit the current?

I am only using a single 24V supply. 
5  Development / Other Hardware Development / Problem with LT1639 Op-Amp on: June 05, 2013, 12:21:58 pm
I am using an Arduino to control a DAC which is then used in conjunction with an LT1639 for a gain of 2.4.  The LT1639 is connected to a 24VAC power supply.

When first giving power, the DAC will send 5V to the LT1639 and I should get 12V back from the LT1639, which I do if I have the multimeter connected before power up.  But if I short it to ground or check it after start up it will show a reading of 1.3V until I cycle the power.  What could be causing this?  I already replaced the op-amp once. 

Thanks!
6  Using Arduino / Programming Questions / Re: Delay without delay help on: February 27, 2013, 04:00:22 pm
Rework it. Make a flowchart (just a simple one) of what you expect to happen when.

You have a couple of things:

  • Button press
  • Time elapsed

If you don't want one dependent on the other, don't put the test for time under the test for the button press.

Thank you for your help.  I have it working now.  Here is what I ended up with. 
Code:
#include <Timer.h>
#include <Relay.h>
#include <Button.h>
#include <Bounce.h>

Button button1(5);
Button button2(6);
Button button3(7);
Relay contactor1(2, true);
Relay contactor2(3, true);
Relay contactor3(4, true);
#define BUTTON 13

int lastButtonState = 0; 
int buttonState = 0;
boolean pthree = 0;

Timer timer1;
Timer timer2;

Bounce bouncer = Bounce( BUTTON,5 );

void setup() {
  button1.begin();
  button2.begin();
  button3.begin();
  contactor1.begin();
  contactor2.begin();
  contactor3.begin();
  pinMode(BUTTON,INPUT);
}

void loop() {
  if (bouncer.update()){
    if (bouncer.read() == HIGH){
      if (button1.read() == HIGH && button2.read() == HIGH && button3.read() == HIGH)
      {
       contactor1.on();
       pthree = 1;
       timer1.resetTimer();
       timer2.resetTimer();
      }
     }
  }
if (pthree == 1){
    if(timer1.timeDelay(3000)){
        contactor2.on();}
    if(timer2.timeDelay(6000)){
        contactor3.on();}
  }
}
7  Using Arduino / Programming Questions / Re: Delay without delay help on: February 25, 2013, 04:04:57 pm


I fixed up your indenting and got rid of the useless "else".

You are checking for buttonState to change, but ignoring the change if the time isn't up. Which is what you are reporting is happening.

Is there a way I can not ignore the change if the time isn't up so that it will change from off to on after the time has elapsed? I appreciate your help. 
8  Using Arduino / Programming Questions / Re: Delay without delay help on: February 22, 2013, 12:15:57 pm
Time to read, understand, and embrace the blink without delay example. You don't need timers, and you don't need to wait for the timer to expire to read switches again.

The timers are just the millis functions in a library.  I understand that I don't need to wait for the count to expire before it reads the switches again.  It is constantly reading the switches, but will only work when time has reached 3 or 6 seconds. 

9  Using Arduino / Programming Questions / Re: Delay without delay help on: February 20, 2013, 03:52:34 pm
The reason you have to hold the button, is because you don't have a Latch. Look at the state change detection code (I can't think of the actual name right now) it's in your example codes. Just implement that into this code and you will be good to go.

I implemented it in this way, but it doesn't work still.  If I repeatedly push the button it will not turn on until the timer has reached it time, but I have to continually push the bottom until the 6 seconds is up.

Code:
#include <Timer.h>
#include <Relay.h>
#include <Button.h>
#include <Bounce.h>

Button button1(5);
Button button2(6);
Button button3(7);
Relay contactor1(2, true);
Relay contactor2(3, true);
Relay contactor3(4, true);
#define BUTTON 13

int lastButtonState = 0; 
int buttonState = 0;// previous state of the button

Timer timer1; // Instantiate a Timer.
Timer timer2;
unsigned long elapsedTime = 3000; // Length of timer in milliseconds.
Bounce bouncer = Bounce( BUTTON,5 );
void setup() {
button1.begin();
  button2.begin();
  button3.begin();
  contactor1.begin();
  contactor2.begin();
  contactor3.begin();
  pinMode(BUTTON,INPUT);// Initialize the serial monitor.
}


void loop() {
  bouncer.update();
  int buttonState = bouncer.read();
  // read the pushbutton input pi

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
     if (buttonState == HIGH && button1.read() == HIGH && button2.read() == HIGH && button3.read() == HIGH){
    contactor1.on();
   if(timer1.timeDelay(3000)){
   contactor2.on();
   }
   if(timer2.timeDelay(6000)){
   contactor3.on();
  }
    }
     
    else {
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;
  }
10  Using Arduino / Networking, Protocols, and Devices / Re: MAX6959 and I2C on: February 10, 2013, 08:34:05 pm
Let's extend setup to be sure that all registers have a valid content:

Code:
void setup()
{
  Wire.begin();
  Wire.beginTransmission(0x38);
  Wire.write(0x01); // register decode mode
  Wire.write(0x00); // disable decode mode for all digits
  Wire.write(0x3f); // intensity max
  Wire.write(0x03); // scan limit 3
  Wire.write(0x03); // normal operation
  Wire.endTransmission();
}

Great!! Thank you! That finally has it working.  BUT you have 0X60 for 1 and it should be 0X30 and for 6 you have 0X1F and it should be 0X5F.  
11  Using Arduino / Networking, Protocols, and Devices / Re: MAX6959 and I2C on: February 10, 2013, 07:04:23 pm
You should have tried with another digit, because digit 0 is in decode mode by default. Insert the following into your setup routine:

Code:
Wire.beginTransmission(0x38);
Wire.write(0x01); // register decode mode
Wire.write(0x00); // disable decode mode for all digits
Wire.endTransmission();

Even with the following code, nothing happens.  What am I doing wrong?
Code:

#include <Wire.h>
byte d[] = { 0x7e, 0x60, 0x6d, 0x79, 0x33, 0x5b, 0x1f, 0x70, 0x7f, 0x7b };

void setup()
{
  Wire.begin();
  Wire.beginTransmission(0x38);
  Wire.write(0x01); // register decode mode
  Wire.write((uint8_t)0x00); // disable decode mode for all digits
  Wire.endTransmission();
}

void set_digit(byte digit, byte value)
{
  Wire.beginTransmission(0x38);
  Wire.write(0x20 + digit);
  Wire.write(d[value]);
  Wire.endTransmission();
}

void loop()
{
  set_digit(3, 1);
}
12  Using Arduino / Networking, Protocols, and Devices / Re: MAX6959 and I2C on: February 10, 2013, 06:12:13 pm
The code does something. You haven't described that.
You want the code to do something. How that differs from what it does isn't clear.

The ball's back in your court.

When I send it that code, the display doesn't show anything.  When I send it that code I would like it to display 0 on digit 0.  
13  Using Arduino / Networking, Protocols, and Devices / Re: MAX6959 and I2C on: February 10, 2013, 12:40:20 am
I probably have the code setup wrong.  But bellow is what I have and it isn't working.  Thank you for your help.
Code:
#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
}
byte d[] = { 0x7e, 0x60, 0x6d, 0x79, 0x33, 0x5b, 0x1f, 0x70, 0x7f, 0x7b };
void set_digit(byte digit, byte value)
{Wire.beginTransmission(0x38);
  Wire.write(0x20 + digit);
  Wire.write(d[value]);
  Wire.endTransmission();
}

void loop()
{
 set_digit(0, 0);
}
14  Using Arduino / Networking, Protocols, and Devices / MAX6959 and I2C on: February 09, 2013, 03:28:19 pm
Hello all,

I am working on a project which requires a four digit seven segment display which is connected to my Arduino with a MAX6959 that interfaces with I2C.  I can get all of the segments to light up with the following display test code.
Code:
#include <Wire.h>

void setup()
{
  Wire.begin();
}


void loop()
{
  Wire.beginTransmission(0b0111000);
  Wire.write(0x07);
  Wire.write(0x01);  
  Wire.endTransmission();
}

But I can't figure out how to control the digits.  Here is a link to the data sheet, http://datasheets.maximintegrated.com/en/ds/MAX6958-MAX6959.pdf

Thanks!
15  Using Arduino / Programming Questions / Re: Delay without delay help on: January 27, 2013, 12:58:57 pm
If it works only one time, then it is because of your delay taken so long and not being able to constantly loop the program. Look at the example blink without delay, that example shows that you can run other things in the background and still blink an LED at 1 second intervals.

I know I can run other things in the background without the delay.  With the delay, it looped fine and I could do it repeatedly.  It wasn't an issue until I switched it to without a delay that there was a problem.  It would stagger startup one time but if I would turn it off then turn it back on the same way I turned it on the first time, it wouldn't stagger the startup.  Does that make sense?

Pages: [1] 2 3 4