connecting your new sensors

Interfacing hardware, sensors, output drivers, chips.
Post Reply
waxweb
Posts: 5
Joined: Sun Dec 14, 2008 5:10 am

connecting your new sensors

Post by waxweb » Sat Mar 20, 2010 10:19 am

hi,
great new products!
I notice that the compass is easily stackable on a bbb...
is there an relatively easy connection for the acceleromter?

and what are you ideas for quik/easiest connection of the sensors to a jeenode [or a rbbb],
after breadboarding?

thanks,
David

paul
Site Admin
Posts: 735
Joined: Mon May 12, 2008 4:19 pm

Re: connecting your new sensors

Post by paul » Sat Mar 20, 2010 4:31 pm

I guess the short answer is that you need to check the pinouts for each sensor. Digging down a bit - with the JeeNode Sensors - and with the modern device sensors, there are two major types - analog and I2C.

Let's take analog first - such as a photocell or our accelerometer. These just need to have GND, and +5 hooked up and the output signals routed to some analog pins.

There is a little trick we use around the shop that works well for both analog and I2C sensors that have a LOW CURRENT DRAW - say under 5 mA. That is to use some pins for power and ground. This could be Arduino digital pins - or analog pins [I'll interject a little rant here and say that having different pin numbers for the analog and digital pin numbers is one of the stupidest things the Arduino team ever did, right up there with the retar... er unfortunate pin 7-8 gap on the boards] This trick can be used with either analog or digital sensors, but you probably want to avoid it sensors (especially analog) drawing more than 5 mA (such as the wind sensor).

I2C sensors.
The native I2C pins on the Arduino (Atmega 168/328) are the analog pins 4&5. The Arduino wire library only addresses these pins. This is a shame because it's perfectly easy to bit-bang (control the pins individually) the I2C protocol. There's a ton of code out there to do this - and maybe in 2014 D. Mellis (chief code honcho for the A team) will get around to adding this in.

So some of our sensors work well using Analog Pins 2&3 for power (with the trick above) and then 4&5 for the I2C lines. You can easily do this on a BBB or RBBB

The JeePlug sensors can be used this way too, but will require a little wiring instead of just plugging them in. In the meantime, Jean-Claude has implemented the bit-banged I2C code so that all of his I2C sensors just plug into the JeeNode port headers and use bit-banged I2C code to read the sensors. So you could also use the Modern Device sensors on JeeNodes but you'd need to remap some header pins. There are some handy little boards for doing this http://www.moderndevice.com/products/je ... ter-boards

So what's with the all the pinouts Jack? Well there a lot of parties involved (I actually didn't design the current black MD sensors - or I would have made the type better on most of them) in collaboration now, and if you know engineers, or least the ones I have come across: They are all convinced that THEY HAVE A BETTER way. So going forward into the future, we plan to use BBB, RBBB and arduiono compatible pinouts on one side of the sensors, and JeeNode compatible pinouts on the other. There is one other issue here which is that the JeeNode operates at 3.3 volts so sensors that won't work at that voltage, will not have the JeeNode pinout. So that people won't call us up and ask why their sensors don't work.

Anyway, now that you are totally confused, the take-home is:

1) Study those pinouts and voltage levels
2) Send me email to ask me what I would do
3) Don't expect me to always be right - what do I look like, God?

Paul

reverendrichie
Posts: 2
Joined: Fri Dec 03, 2010 11:29 am

Re: connecting your new sensors

Post by reverendrichie » Fri Dec 03, 2010 11:41 am

Paul, is there any sample code available for the MMA7361 Accelerometer?

Thank you.

paul
Site Admin
Posts: 735
Joined: Mon May 12, 2008 4:19 pm

Re: connecting your new sensors

Post by paul » Fri Dec 03, 2010 12:12 pm

The sensors are just analog so I always start out with the Arduino Sketch AnalogReadSerial (confusing sketch names by the way)

Code: Select all

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

void loop() {
  int sensorValue = analogRead(0);
  Serial.println(sensorValue, DEC);
}
Just triple it up for the other channels, and you have to fuss with the serial print formatting a bit too.

Code: Select all

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

void loop() {
    int sensorValue1 = analogRead(0);  //  x pin on 0 etc.
    int sensorValue2 = analogRead(1);
    int sensorValue3 = analogRead(2);
    Serial.print(sensorValue1, DEC);
    Serial.print("       ");
    Serial.print(sensorValue2, DEC);
    Serial.print("       ");
    Serial.println(sensorValue3, DEC);
}

reverendrichie
Posts: 2
Joined: Fri Dec 03, 2010 11:29 am

Re: connecting your new sensors

Post by reverendrichie » Fri Dec 03, 2010 12:25 pm

Thank you, this is what I thought but I wanted to verify it. follow-up question, is there a faster way than using analogread? Reason I ask this is, I am considering using this device in an IMU flight control system.

Post Reply