Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: Whats up with android and arduino? on: May 16, 2011, 09:33:25 pm
Amarino developed a bluetooth api to handle events to and from arduino and android. It's basically a glorified serial parser but it works well and is easy to use. They also have a somewhat active support group if I'm not mistaken.
2  Using Arduino / Project Guidance / Re: HELP ME!!! Desperation! on: May 16, 2011, 08:50:51 pm
Have you gotten the knock sensor to work by itself? It's usually a good idea to get each component working before you start merging them.

If you're able, test your knock sensor to find your ideal threshold. This can be done by using a Serial.print(sensorReading); and watching the serial monitor in the Arduino IDE

Once you've established the threshold, it's time to merge all of the components. I would imagine it would look something like this:

Code:
#include <Servo.h>

//Servo
Servo first; // create servo object
Servo second; // create servo object
#define firstservopin 8
#define secondservopin 7

//Knock Sensor
#define knockSensor A0
const int threshold = 100; //Sensitivity of the Knock Sensor
int sensorReading;

void setup() {
  first.attach(firstservopin); // attach the servo to digital output 8
  second.attach(secondservopin); // attach the servo to digital output 7
  first.write(90); // center the servo
  second.write(90); // center the servo
}

void loop() {
  sensorReading = analogRead(knockSensor);
  
  if (sensorReading >= threshold) {    
    first.write(0);                        // move first servo to pos 0
    second.write(0);                 // move second servo to pos 0
    delay(1000);
    first.write(120);               // move first servo to pos 120
    second.write(120);         // move second servo to pos 120
    delay(1000);
  }
}

3  Using Arduino / Project Guidance / Re: DC voltage inverting on: May 14, 2011, 03:59:50 pm
I basically have one shot to get this right so I was hoping that someone could take a look at my schematic and just confirm I'm doing this correctly. I used the rugged circuits design and left in the small positive offset.

I selected the same op amp used in rugged circuits design(I think) http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=296-13057-1-ND
schematic here http://i.imgur.com/MTtJB.png

Thanks
4  Using Arduino / Project Guidance / Re: DC voltage inverting on: May 13, 2011, 05:55:26 pm
thanks for the replies, they've helped greatly!
5  Using Arduino / Project Guidance / DC voltage inverting on: May 13, 2011, 02:25:29 am
I've been working on a -2kV power supply that requires a high side current monitor. I need to read four -2.5V~0V DC channels. I just realized that the arduino's adc's can't read negative voltages.  I've already begun populating the board and need to make this work. The only voltage inverters I've seen have a floor of about 1.5V. What's the best way to get my voltages in the positive range to be read by the adc. I'm already using all of my digital pins so this would have to be some kind of break-out board.

Thanks for any advice in advance
6  Topics / Science and Measurement / High side current measurements on: February 09, 2011, 01:24:43 am
Hi all, I'm working on a adjustable 0-2kV power supply. I'm interested in taking a high side current measurement to monitor for excessive current draw from a PhotoMultiplier Tube. The typical current draw should be between 0.5mA to 2mA. However, from my understanding as the tubes start to go bad they begin drawing more current, up to 20mA. I will be reading the current through an analog input on the Arduino and displaying it to an LCD. The PMT is ~5Mohm IIRC.

My first thought is to make a current divider circuit but I'm somewhat hesitant to have so much potential so near the Arduino. Is this okay as long as I'm biased to ground?

If not, what is the best way to go about safely taking these measurements on the Arduino?

I've read a little bit about isolation amplifiers, and they seem like it might be the right approach but I don't fully understand how to go about implementing one. Any thoughts?

Thanks
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: SPI how-to on: December 10, 2010, 08:53:20 pm
scswift, do you mind posting your entire code? It would be very appreciated.
8  Forum 2005-2010 (read only) / Interfacing / Re: SPI + rotary encoder = frozen arduino on: December 24, 2010, 03:46:23 am
I'm a bit embarrassed to say this but my problem was with my SPI function. When I migrated from digitalWrite to port manipulation I neglected to leave the dac's reset pin high. It does seem odd though that it would respond for a few seconds before shutting down.

After getting this straight I decided to trying polling the encoder again and it proved to be more than adequate.

Thanks for the help and clarification.
9  Forum 2005-2010 (read only) / Interfacing / Re: SPI + rotary encoder = frozen arduino on: December 22, 2010, 11:44:28 pm
I've tried several different takes on this, this just happens to be what I have saved at the moment.

Code:
#include <SPI.h>

enum PinAssignments {
  encoderPinA = 2,
  encoderPinB = 3
};

#define SCK 13 //Clock
#define MOSI 11 //MOSI
#define RST 12

//channel address'
static byte DACA = 0x10;
static byte DACB = 0x12;
static byte DACC = 0x14;
static byte DACD = 0x16;

//Channel values
volatile unsigned int valA, valB, valC, valD; //not in use yet
volatile unsigned int encoderPos;
unsigned int lastReportedPos = 1;

boolean A_set = false;
boolean B_set = false;


void setup(){
  //=====DAC
  DDRB = B00111100; //sets my SPI ports as outputs
  digitalWrite(RST,LOW); //required for the dac
  SPI.begin();
  SPI.setDataMode(SPI_MODE1);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV4); //I've tried 2-16 w/ the same results
  digitalWrite(RST,HIGH); //Starts all dac channels at 0x00
  
  //=====Encoder
  pinMode(encoderPinA, INPUT);
  pinMode(encoderPinB, INPUT);
  digitalWrite(encoderPinA, HIGH);  // turn on pullup resistor
  digitalWrite(encoderPinB, HIGH);  // turn on pullup resistor
  attachInterrupt(0, doEncoderA, CHANGE);
  attachInterrupt(1, doEncoderB, CHANGE);
}

void loop(){
  if (lastReportedPos != encoderPos) {
    dacWrite(DACA,encoderPos);
    lastReportedPos = encoderPos;
  }
}

dacWrite function
Code:
void dacWrite(byte dacActive, int dacValue){
  PORTB = 0x04; //toggles latch, Pin 10
  SPI.transfer(dacActive); //command byte
  SPI.transfer(highByte(dacValue));
  SPI.transfer(lowByte(dacValue));
  PORTB = 0x00;
}

doEncoder function from the playground.
Code:
void doEncoderA(){
  A_set = digitalRead(encoderPinA) == HIGH;
  encoderPos += (A_set != B_set) ? +1 : -1;
}

void doEncoderB(){
  B_set = digitalRead(encoderPinB) == HIGH;
  encoderPos += (A_set == B_set) ? +1 : -1;
}

I've also tried using direct port manipulation for the doEncoder function. I believe retrolefty posted this in a different thread. Obviously the rest of the sketch was changed to use this code. In this setup I was just using a single interrupt to lessen its impact.
Code:
void doEncoderA() {
    if (PIND & 0x04) {                              // test for a low-to-high interrupt on channel A, same as if(digitalRead(encoderPinA) == HIGH)
        if ( !(PIND & 0x10)) {                      // check channel B for which way encoder turned, same as if(digitalRead(encoderPinB) == LOW)
           encoderPos = ++encoderPos;               // CW rotation
           PORTD = PIND | 0x40;                     // set direction output pin to 1 = forward, same as digitalWrite(encoderdir, HIGH);
          }
        else {
           encoderPos = --encoderPos;               // CCW rotation
           PORTD = PIND & 0xBF;                      // Set direction output pin to 0 = reverse, same as digitalWrite(encoderdir, LOW);
          }
    }
    else {                                          // it was a high-to-low interrupt on channel A
        if (PIND & 0x10) {                          // check channel B for which way encoder turned, same as if(digitalRead(encoderPinB)==HIGH)
           encoderPos = ++encoderPos;               // CW rotation
           PORTD = PIND | 0x40;                     // Set direction output pin to 1 = forward, same as digitalWrite(encoderdir, HIGH);
           }
        else {
           encoderPos = --encoderPos;               // CCW rotation
           PORTD = PIND & 0xBF;                      // Set direction output pin to 0 = reverse, same as digitalWrite(encoderdir, LOW);
           }
         }
    PORTD = PIND | 0x80;                            //  digitalWrite(encoderstep, HIGH);   generate step pulse high
    PORTD = PIND | 0x80;                            //  digitalWrite(encoderstep, HIGH);   add a small delay
    PORTD = PIND & 0x7F;
    
    dacWrite(DACA,encoderPos);                            //  digitalWrite(encoderstep, LOW);    reset step pulse
}      
10  Forum 2005-2010 (read only) / Interfacing / SPI + rotary encoder = frozen arduino on: December 22, 2010, 07:37:17 pm
Hi all, My project involves controlling a quad 16-bit dac through spi from a single rotary encoder. I've spent quite a few hours trying to figure this out but am getting nowhere.

I've got my dac(TI 8555) working just fine using the SPI library, and for the most part have my encoder(ENC1J-D28-L00128L-ND) working fine by itself.

The problem I'm having is that when I combine the code for the dac and the encoder my arduino appears to be freezing after ~4s regardless of whether or not I turn the encoder. I've tried polling the encoder but due to my lack of foresight I purchased an encoder that has too many steps/rev and at moderate-high speeds I begin to lose steps.

I've read that delay() does not work inside of interrupts. This could be a possible hangup if I assume the SPI library must use some kind of delay in order for setClockDivider() to function.

Another thought I had was that interrupts are being temporarily disabled and qued during the function associated with the interrupt. I know that SPI uses some form of interrupt and this also could be causing an issue.


A few other constraints that need to be kept in mind:

I will be adding in a 4x40 char LCD. I've also got this working fine by itself but am worried the time needed to run the SPI code and update the LCD will limit my options using either interrupts or polling of the encoder.

I don't need the dac to be updated for every increment/decrement of the encoder. I do, however, need the encoder position to be updated fairly accurately.



I don't mind doing the leg work on this but a little bit of insight or a kick in the right direction would greatly appreciated. Thanks!
Pages: [1]