Show Posts
Pages: [1] 2 3
1  Development / Other Software Development / Re: Mods to HardwareSerial to handle 9-bit data on: July 25, 2013, 01:06:49 pm
Hi Nick et al.,
I know this topic is fairly old, but figured it was best to ask the question here vs. starting a new thread?

I recently got involved in a project where 9-bit serial data was required, and not really knowing what to do I was pretty excited to see Nick's work here (thanks, Nick!).

So my quick question is whether or not the mods to the library are specific to AVR-based micros, or more specifically will the mod work with ARM-based micros? I just don't know enough about how libraries work (yet) to be able to answer this question myself.

Thanks in advance for any pointers, and thanks again Nick for your work here!

Cheers,
David
2  Using Arduino / Project Guidance / Re: nRF24L01 + tlc5940 on the same board on: November 15, 2012, 08:25:16 pm
I don't believe so. Plus xlat is on a pin that isn't shared by the nRF24L01, which means I'm even further from figuring this out smiley-sad I'll poke around and see if there is any more info on xlat, however.

Thanks for your help!
David
3  Using Arduino / Project Guidance / nRF24L01 + tlc5940 on the same board on: November 15, 2012, 03:10:47 pm
Hi all,
I've been trying to figure this out for a few days now and haven't had much luck. On the same board I have both a nordic nRF24L01+ wireless radio (using the RF24 lib) and the tlc5940 led driver. both use the hardware spi, however the tlc5940 has no cs/ss pin, which I believe is currently the root of my problems. Has anybody had an success getting these two boards to play nice on the same micro?

FYI: I'm currently using a teensy v2. I don't think this should make a difference, but just in case.

Thanks,
David
4  Using Arduino / Networking, Protocols, and Devices / mpr121 - help reading filtered data on: September 29, 2011, 07:57:20 pm
Hi all,
I'm looking for a little guidance communicating with the mpr121 capacitive sensor (i.e. http://www.sparkfun.com/products/9695).
I'm trying to read the 10bit filtered data from the sensors vs. the touch data, but seems no matter what I do, I can't get anything but the touch data. I'm hoping it's a matter of having a register set wrong, but I've gone through the docs several times and am just not seeing it.

Here's my sketch:

Code:
#include "mpr121.h"
#include <Wire.h>

int ele0_msb = 0;
int ele0_lsb = 0;

unsigned long currenttime = 0;
unsigned long nextsample = 0;
int sampleinterval = 20;
boolean sampleflag = 0;

void setup(){
  Serial.begin(9600);
  Wire.begin();

  mpr121_setup();
}

void loop(){
  currenttime = millis();
  if (currenttime >= nextsample) {
    nextsample = currenttime + sampleinterval;
    readData();
  }

}


void readData() {


  Wire.beginTransmission(0x5A);  // begin communication with the MPR121 on I2C address 0x5A
  Wire.send(0x04);  // read ELE0 filtered data LSB
  Wire.send(0x05);  // read ELE0 filtered data MSB
  Wire.requestFrom(0x5A, 2);     // request for the MPR121 to send 2 bytes

  // check to see if we've received the byte over I2C
  if(Wire.available() >= 2)
  {
    ele0_lsb = Wire.receive();
    ele0_msb = Wire.receive();

  }
  Wire.endTransmission();        // ends communication

  sendData();
}

void sendData() {
  Serial.print(ele0_msb, BYTE);
  Serial.print(ele0_lsb, BYTE);
  Serial.print(10, BYTE);
}



void mpr121_setup(void){

  // Section A - Controls filtering when data is > baseline.

  set_register(0x5A, MHD_R, 0x01);
  set_register(0x5A, NHD_R, 0x01);
  set_register(0x5A, NCL_R, 0x00);
  set_register(0x5A, FDL_R, 0x00);

  // Section B - Controls filtering when data is < baseline.
  set_register(0x5A, MHD_F, 0x01);
  set_register(0x5A, NHD_F, 0x01);
  set_register(0x5A, NCL_F, 0xFF);
  set_register(0x5A, FDL_F, 0x02);



  // Section C - Sets touch and release thresholds for each electrode
  set_register(0x5A, ELE0_T, TOU_THRESH);
  set_register(0x5A, ELE0_R, REL_THRESH);

  set_register(0x5A, ELE1_T, TOU_THRESH);
  set_register(0x5A, ELE1_R, REL_THRESH);

  set_register(0x5A, ELE2_T, TOU_THRESH);
  set_register(0x5A, ELE2_R, REL_THRESH);

  set_register(0x5A, ELE3_T, TOU_THRESH);
  set_register(0x5A, ELE3_R, REL_THRESH);

  set_register(0x5A, ELE4_T, TOU_THRESH);
  set_register(0x5A, ELE4_R, REL_THRESH);

  set_register(0x5A, ELE5_T, TOU_THRESH);
  set_register(0x5A, ELE5_R, REL_THRESH);

  set_register(0x5A, ELE6_T, TOU_THRESH);
  set_register(0x5A, ELE6_R, REL_THRESH);

  set_register(0x5A, ELE7_T, TOU_THRESH);
  set_register(0x5A, ELE7_R, REL_THRESH);

  set_register(0x5A, ELE8_T, TOU_THRESH);
  set_register(0x5A, ELE8_R, REL_THRESH);

  set_register(0x5A, ELE9_T, TOU_THRESH);
  set_register(0x5A, ELE9_R, REL_THRESH);

  set_register(0x5A, ELE10_T, TOU_THRESH);
  set_register(0x5A, ELE10_R, REL_THRESH);

  set_register(0x5A, ELE11_T, TOU_THRESH);
  set_register(0x5A, ELE11_R, REL_THRESH);

  // Section D
  // Set the Filter Configuration
  // Set ESI2
  set_register(0x5A, FIL_CFG, 0x04);

  // Section E
  // Electrode Configuration (register 0x5E)
  // Set ELE_CFG to 0x00 to return to standby mode
  // Set ELE_CFG to 0x0C to turn on just touch
  // Set ELE_CFG to 0x30 to turn on proximty for all electrodes
  // Set ELE_CFG to 0x3C to turn on BOTH proximity and touch
  set_register(0x5A, ELE_CFG, 0x30);

  /*
  // Section F
   // Enable Auto Config and auto Reconfig
   set_register(0x5A, ATO_CFG0, 0x0B);
   set_register(0x5A, ATO_CFGU, 0xC9);  // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V   set_register(0x5A, ATO_CFGL, 0x82);  // LSL = 0.65*USL = 0x82 @3.3V
   set_register(0x5A, ATO_CFGT, 0xB5);  // Target = 0.9*USL = 0xB5 @3.3V
   
   */

}


void set_register(int address, unsigned char r, unsigned char v){
  Wire.beginTransmission(address);
  Wire.send(r);
  Wire.send(v);
  Wire.endTransmission();
}


In a nutshell, I'm trying to read from registers 0x04 and 0x05 (LSB and MSB for electrode 0 data), but I seem to only get 0x00 and 0x01.
For those that have worked a bit with this sensor, any ideas?

Thanks in advance for any pointers.

David
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: analogRead and generating checksum values on: September 18, 2010, 11:15:35 am
something like this (am away from my arduino at the moment, so coding a bit blind):

int touchStrip = 0;
char touchStripBuf[8];

touchStrip = analogRead(touchStripPin);
itoa(touchStripPin, touchStripBuf, 10);
for (int i = 0; i < 8; i++) {
      if (touchStripBuf == 10) {
            break;
      }
    else {
        checksum += touchStripBuf;
    }
}

Thanks,
David
6  Forum 2005-2010 (read only) / Syntax & Programs / analogRead and generating checksum values on: September 18, 2010, 10:41:25 am
Hi all,
I think I've been sniffing too many solder fumes, because this question sound pretty straightforward, but I can't seem to figure it out.

Here's my set-up:
I have a couple sensors that pass data via UART to different Rx pins on the mega. I merely read these values, add them to an uberpacket and pass along wirelessly to the host computer on the main Tx pin on the mega. The second-to-last byte in the uberpacket is a checksum value based on all the data in the packet (last packet is line feed, dec 10). The values being read from the other sensors are ascii values, so for 10.5 I read 49 48 46 53. I'm merely passing these values directly, so my checksum is based on 49 49 46 53 (and so on). Everything works great, and can easily verify packets on the receiving machine.

No I am adding data from an analog pin on the mega to the packet. Let's say I get the value of 500 from an analog read. I'm passing this along as an int as part of my uberpacket, and on the receiving end I get 53 48 48. My problem is now calculating the checksum. On the mega it's using the value 500 for the checksum calculation, but on the receiving machine it uses 53, 48 , and 48.

I'm guessing that what I need to do is convert 500 to ascii via itoa() for the checksum? Does this sound right?

Thanks in advance for any pointers.

Best,
David
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: need a bit of itoa help on: July 08, 2009, 01:36:03 am
Perfect!
Thanks for the nudge!
Best,
David
8  Forum 2005-2010 (read only) / Syntax & Programs / need a bit of itoa help on: July 07, 2009, 10:14:24 pm
Hi all,
Need some advice on converting a series of ascii ints into the number they actually make up (e.g. 49 48 48 >> 100). Currently I'm reading data from a digital compass (heading, pitch, & roll) using newsoftserial. Usually I've been simply passing the data to the UART Tx and that's that. Now I actually want to use the data to do some onboard processing. The packet from the compass is three floats, separated by commas, ending in both a carriage return and line feed. Heading is always positive (0. - 360.), pitch and roll positive or negative (-90. to +90, -180. to +180., respectively).  Breaking up the packet isn't that difficult thanks to the commas and line feed. My hurdle is converting "49 49 48 46 53" into "110.5", and then using it as a float in other calculations on the arduino. itoa is what I would use on the mac side...and it seems like this is what I should use on the arduino side, but I'm not finding much info, and my attempts so far won't even compile. Any advice on references or example code...or even a different method?

Thanks in advance!

David
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: read sensor data while doing something else on: January 17, 2009, 02:08:14 pm
Thank you both for your help!  It makes sense...I think! Now trying to decide if I should attempt this on the Arduino, or just in Max where my programming chops are considerably more proficient  smiley Actually the more I think about it, it might not be TOO beyond what I can do on the Arduino...nice little challenge, at least!

Thanks again!
David

10  Forum 2005-2010 (read only) / Syntax & Programs / read sensor data while doing something else on: January 17, 2009, 12:57:57 am
Hi all,
First post here! I'm a bit new to Arduino, so have perhaps a bit of n00b question. I have an arduino mini pro talking to MaxMSP. After much trial and error (and reading some great help on this forum!), I have my sketch and patch set-up nicely so I can read analog and digital input from some pins while sending PWM data to others.

I'm now trying to get a few more functions onto the arduino. Here's where I am stuck: if I receive an 'f' (followed by some extra numbers) from Max, I want to flash some LEDs. The part is all workin' dandy. My problem is that while the LEDs are flashing, I do not want to stop receiving data form the sensors during this time. Right now this isn't the case...as soon as I call the function to flash the LEDs, everything else stops. Is it possible to do what I want? I could certainly do the "flash" in Max instead, but would like to minimize traffic on the serial port if I can.

Here's my sketch.

Thanks in advance!
Best,
David

Code:
int ledPin = 13; // status LED on Arduino
int pwmOne = 6;  // pin 6 = PWM LED output 1
int pwmTwo = 9;  // pin 9 = PWM LED output 2
int compass = 10; // pin 10 = power for compass
int inByte = 0; // container to hold incoming serial data
int byteCounter = 0;
int command = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;


void setup()
{
  Serial.begin(57600);               // 115200 is the default Arduino Bluetooth speed
  pinMode(ledPin, OUTPUT);            // declare LED as output
  pinMode(2, INPUT);            // declare pin 2 as digital input
  pinMode(4, INPUT);            // declare pin 4 as digital input
  pinMode(pwmOne, OUTPUT);            // declare pin 6 as output
  pinMode(pwmTwo, OUTPUT);            // declare pin 9 as output
  pinMode(compass, OUTPUT);           // declare pin 9 as output


  for (int i=0; i <= 25; i++){ // flash all LEDs once a connection is made
    digitalWrite(ledPin, HIGH);
    analogWrite(pwmOne, 255);
    analogWrite(pwmTwo, 255);
    delay(20);
    digitalWrite(ledPin, LOW);
    analogWrite(pwmOne, 0);
    analogWrite(pwmTwo, 0);
    delay(20);
  }

}


void loop()
{
  while (Serial.available() > 0) { // Check serial buffer for any data

    inByte = Serial.read();
    //                 Serial.print("raw value = ");
    //                 Serial.println(inByte);

    if (inByte == '$') { // reset character = $
      byteCounter = 0;
      command = 0;
      val1 = 0;
      val2 = 0;
      val3 = 0;
      //                        Serial.println("reset");
    }
    else if (inByte != 13 && inByte != 36 && byteCounter == 0) { // first value of list = command
      command = inByte;
      //                        Serial.print("command byte = ");
      //                        Serial.println(command);
      byteCounter++; // increase byteCounter by 1
    }
    else if (inByte != 13 && inByte != 36 && byteCounter == 1) { // PWM pin # OR flash time part 1
      val1 = inByte;
      //                        Serial.print("val1 =");
      //                        Serial.println(val1);
      byteCounter++; // increase byteCounter by 1
    }
    else if (inByte != 13 && inByte != 36 && byteCounter == 2) { // PWM value OR flash time part 2
      val2 = inByte;
      //                       Serial.print("val2 =");
      //                       Serial.println(val2);
      byteCounter++; // increase byteCounter by 1
    }
    else if (inByte != 13 && inByte != 36 && byteCounter == 3) { // flash time intensity
      val3 = inByte;
      //                       Serial.print("val3 =");
      //                       Serial.println(val3);
      byteCounter++; // increase byteCounter by 1
    }
    else if (inByte == 13) {
      //                        Serial.println("end of command");
      //                  Serial.flush();
      //                  delay (10); // make sure we aren't overloading anything
    } // end if

    if (command == 'r') { // If command 'r' is received then read the pins
      digitalWrite(ledPin, HIGH); // turn on the status LED
      Serial.print("wand "); // sets a header for the data

      // read analog pins
      int a0 = analogRead(0); // read analog input 0
      Serial.print("a0=");
      Serial.print(a0);
      int a1 = analogRead(1); // read analog input 1
      Serial.print("a1=");
      Serial.print(a1);
      int a2 = analogRead(2); // read analog input 2
      Serial.print("a2=");
      Serial.print(a2);

      // read digital pins
      int d2 = digitalRead(2); // read button value on pin 2
      Serial.print("d2=");
      Serial.print(d2);
      int d4 = digitalRead(4); // read button value on pin 4
      Serial.print("d4=");
      Serial.print(d4);

      Serial.println(); // Send a carriage return to mark end of pin data.
      digitalWrite(ledPin, LOW); // turn off the status pin

    } // end command = 'r'

    // If a 'w' is received then write data to the output pins
    if (command == 'w' && byteCounter == 3) {
      analogWrite(val1, val2);
    } // end if command = 'w'

    // If a 'c' = 99 is received then toggle power pin for compass
    if (command == 'c') {
      digitalWrite(compass, HIGH); // turn on the compass
      Serial.println("turning on compass");
      delay (10); // delay to make sure compass sends data.
      digitalWrite(compass, LOW); // turn off the compass
      Serial.println("turning off compass");
    } // end if command = 'c'

    // If an 'f' is received, flash the LEDs based on value for val1
    if (command == 'f' && byteCounter == 4) {  // flash them LEDs
      flashLEDs(val1,val2,val3);
      command = 0;
      val1 = 0;
      val2 = 0;
      val3 = 0;
    } // end if command = 'f'

  } // end while

} // end loop


void sendValue (int x){               // function to send the pin value followed by a "space".
  Serial.print(x);
  Serial.print(32, BYTE);
}

void flashLEDs(int a, int b, int c) {
  int flashtime = ((a * 1000)+(b * 10)) / 40; // gives resolution of hundreth of second
  Serial.print("a =");
  Serial.println(a);
  Serial.print("b =");
  Serial.println(b);
  Serial.print("Flash time =");
  Serial.print(flashtime * 40);
  Serial.print(" Intensity =");
  Serial.println(c);
  for (int i=0; i <= flashtime; i++){
    analogWrite(pwmOne, c);
    analogWrite(pwmTwo, c);
    delay(20);
    analogWrite(pwmOne, 0);
    analogWrite(pwmTwo, 0);
    delay(20);
  } //end for loop
} // end of flashLEDs

11  Forum 2005-2010 (read only) / Interfacing / Re: uploading new sketches to occupied UART ports on: November 04, 2009, 05:11:34 pm
Hi MikMo,
Thanks for your reply. Unfortunately I haven't had any success with that...still seems to "bypass" the mini which is why I'm thinking an inline resistor might help here to ensure the sketch goes to the mini and not beyond. I just don't know if this is smart, tho.

Thanks,
David
12  Forum 2005-2010 (read only) / Interfacing / uploading new sketches to occupied UART ports on: November 04, 2009, 01:10:51 pm
Hi all,
I'm having a bit of difficulty even getting a sensible subject header, but let's hope my question makes more sense!

My setup: I have an arduino pro mini. I usually upload sketches by connecting to the pins at the end of the board. I am only connected to the pins at the end when uploading sketches...otherwise they are open. At the same time I have an xbee attached to the Tx & Rx pins on the side (it's just an alternate location to connect to the same UART pins on the chip). In addition I usually have some other device (e.g compass or rfid reader) attached to the other pins on the arduino and communicate via newsoftserial.

The set-up works great while it's running. The problem, however, is when I want to upload a new sketch. Due to the crazy physical space limitations these devices need to live in, I usually have to solder the wires directly to the boards...often takes up considerably less space than using jumpers and the like. Since the xbee is permanently connected to the Tx & Rx UART pins, I get errors when trying to upload new sketches using the open UART pins, usually something along the line of unable to communicate to the arduino. I am assuming it's because data is flowing to the xbee as well.

So the question: is there a way to have the xbee permanently attached to the Tx and Rx pins, and still be able to upload sketches to the mini? A cleverly placed resistor or diode or ??

Thanks in advance for any advice, and please let me know if any of the above doesn't make sense. I seem to be struggling with how to word the question.

Cheers,
David
13  Forum 2005-2010 (read only) / Development / Re: using both serial and newsoftserial on: July 05, 2009, 12:32:57 am
Thank you for the reply, Mikal. Very helpful knowing a bit more what is happening behind the scenes quantitatively. Before I completely abandon my quest here, I'll play around a bit with the baud rates and see if I can't maybe find a happy medium.

Thank you all again! This has all been very helpful!

Best,
David
14  Forum 2005-2010 (read only) / Development / Re: using both serial and newsoftserial on: July 04, 2009, 11:22:56 pm
OK, then that really does support what I am seeing.
I could speed up the soft-serial baud or slow down the UART, but will it really make a difference? In the end, once I reconnect all these mini's, the last arduino is reading ~80 bytes of data from the UART and ~20 bytes from the soft-serial, then writing 2 separate xbee API packets. In other words, time to fire up another xbee and arduino and have that deal with the compass data separately.

Thank you all for your help! Of course if you have a brilliant suggestion, please don't hesitate to keep sharing smiley

Cheers,
David
15  Forum 2005-2010 (read only) / Development / Re: using both serial and newsoftserial on: July 04, 2009, 03:31:29 pm
actually I don't even need to recompile...I just power down the device (compass) attached to the soft-serial port (so there is no data to read) and I get hours of good clean data from the UART ports.
Pages: [1] 2 3