Printable Version | Subscribe | Add to Favourites
New Topic New Poll New Reply
Author: Subject: Arduino help needed
MikeR

posted on 22/9/12 at 11:23 PM Reply With Quote
Arduino help needed

started playing with an Arduino and I'm struggling the the electronics part. does anyone know a good forum or can explain pull up resistors on the wire / I2C interface? I can detect a device on the interface but can't talk to it. I think its cause I'm using 3.3v and a 3k resistor instead of 5v and 10k. didn't want to use 5v as I foot want to risk blowing up the Chinese board I'm trying to interface with that has no instructions.

car link is I want to do car stuff with it once complete.

View User's Profile View All Posts By User U2U Member
mad4x4

posted on 23/9/12 at 12:41 AM Reply With Quote
A pull up resistor will force the signal on the pin to "Pull up" to the rail voltage in your case 3.3v

A Pull down resistor will drive the signal ping to Gnd.

A pull up resistor is used when the signal is active low and you want the pin to default to 1 a pull down will give you a default of 0.





Scot's do it better in Kilts.

MK INDY's Don't Self Centre Regardless of MK Setting !

View User's Profile Visit User's Homepage View All Posts By User U2U Member
BangedupTiger

posted on 23/9/12 at 12:49 AM Reply With Quote
Unfortunatley I can't help you, but hopefully you can help me.

Do you know where I could get an Arduino 4 pin plug? been after one for ages.

Cheers

View User's Profile View All Posts By User U2U Member
nick205

posted on 23/9/12 at 06:28 AM Reply With Quote
pop me a u2u reminder and I'll dig out the forum details for you.

Excellent bit of kit (much more practical than the raspberry pi) we use it at work for prototye and test work.






View User's Profile View All Posts By User U2U Member
v8kid

posted on 23/9/12 at 06:55 AM Reply With Quote
quote:
Originally posted by nick205
pop me a u2u reminder and I'll dig out the forum details for you.

Excellent bit of kit (much more practical than the raspberry pi) we use it at work for prototye and test work.


Ah I thought the pi could emulate the arduono but with better input/output functionality?

Cheers!





You'd be surprised how quickly the sales people at B&Q try and assist you after ignoring you for the past 15 minutes when you try and start a chainsaw

View User's Profile E-Mail User Visit User's Homepage View All Posts By User U2U Member
digiman

posted on 23/9/12 at 07:34 AM Reply With Quote
If you are using USB to power the arduino, then it will be using internal pull ups to the 5v rail. I2C is on pins A4 and A5, make sure you have got them the right way round.
View User's Profile View All Posts By User U2U Member
gremlin1234

posted on 23/9/12 at 11:11 AM Reply With Quote
quote:

I'm using 3.3v and a 3k resistor instead of 5v and 10k.

3.3v and 3k means the interfaced board has to sync 1.1mA
the 5v 10k, is only syncing 0.5mA
try it with the 10k pull up at 3.3 volt

View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 23/9/12 at 01:52 PM Reply With Quote
The I2C interface uses "open collector" outputs. This means the output driver can only sink current (i.e. pull the line to ground), or become high imepdance (floating). The resistor is required to pull the data/clock lines to Vcc when the output is floating.

This scheme allows both a master and the slave device to communicate over the same wire, i.e. either device can pull the line to ground without causing a logic conflict and possibly damaging high currents as would happen if you tried to connect two push-pull outputs together.

I presume you are sending the slave address to the peripheral and are getting an ACKnowlegde back from it, but are having trouble from that point?

Happy to look over the code if you can give details of the slave device.

[Edited on 23/9/12 by MikeRJ]

View User's Profile View All Posts By User U2U Member
MikeR

posted on 23/9/12 at 09:52 PM Reply With Quote
Hopefully respond better tomorrow. I got the following device from tatbay and haven't got any instructions....

10DOF L3G4200D+ADXL3​45+HMC5883L+BM​P085 sensor for arduino | eBay

now i don't want to put 5v through it (although it has a 5v pin) as i'm worried about blowing it. I've run a i2c port scanner and got a response that 4 devices exist using 3.3v on the 3.3v pin and what ever resistor on the i2c pins i said earlier. Figured out which should be the ADXL345 but can't then get it to talk to me.

Got no instructions on how the board should be used / set up etc.

View User's Profile View All Posts By User U2U Member
Confused but excited.

posted on 23/9/12 at 10:30 PM Reply With Quote
quote:
Originally posted by gremlin1234
quote:

I'm using 3.3v and a 3k resistor instead of 5v and 10k.

3.3v and 3k means the interfaced board has to sync 1.1mA
the 5v 10k, is only syncing 0.5mA
try it with the 10k pull up at 3.3 volt


Computer geeks. It has to sink 1.1mA, not sync it.





Tell them about the bent treacle edges!

View User's Profile View All Posts By User U2U Member
MikeR

posted on 24/9/12 at 06:57 AM Reply With Quote
I picked the resistor size after reading lots of web pages and people using lots of different sizes . I then just guessed at a size in a completely non scientific way.
View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 24/9/12 at 10:59 AM Reply With Quote
The resistor value depends on the speed of the bus (i.e. bit rate) and the amount of capacitance on the lines (caused by input capacitance of the slave devices and any stray capacitance from SCL/SDA to ground).

If your resistor value is too high for the amount of capacitance and bit rate, the clock and data lines may not reach a logic '1' level before the next falling edge. Even if it does, excessively slow rise times can cause problems, especially if SCL and SDA are not evenly matched. The master and slave peripherals will almost certainly specify a minimum rise time.

The lower limit on the resistor value is the amount of current that the pins can sink on the master and slave devices. Going unnecessarily low will increase current consumption for no gain.

For 100Khz on a 3.3v bus 3k should be fine unless you have an unusual amount of capacitance on the lines. If you are using 400kHz clock you might want to reduce that down to 1.5-2k, but really the only way you are going to find the optimum value is by using a scope to measure the rise times on SDA/SCL. You can add up all the input capacities of the slaves, add a 100pF or so for stray capacitance and then do some maths, but without the scope you won't be able to verify anything.

By the way, you are right be be cautious about signal levels, the I2C devices on your board all appear to be 3.3v devices, so you need to stick to a 3.3v levels on your I2C bus. If your I2C levels exceed the slave supply voltage, then it will cause protection diodes to conduct on the slave inputs which can cause all sorts of odd behavior.

View User's Profile View All Posts By User U2U Member
MikeR

posted on 25/9/12 at 10:05 AM Reply With Quote
Think i may have found the problem. With tired eyes and 1/4w resistors orange and red looks very similar. I had 3 orange stripes instead of 3 red on the pull ups. Swapped the resistors last night and will hopefully test tonight.
View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 25/9/12 at 12:29 PM Reply With Quote
33k would certainly be high enough to stop it working!
View User's Profile View All Posts By User U2U Member
mad4x4

posted on 25/9/12 at 02:52 PM Reply With Quote
Try these guys

They have lots of Ardiuno & Rasp PI Stuff SHould have the connector your after





Scot's do it better in Kilts.

MK INDY's Don't Self Centre Regardless of MK Setting !

View User's Profile Visit User's Homepage View All Posts By User U2U Member
ceebmoj

posted on 25/9/12 at 03:25 PM Reply With Quote
quote:
Originally posted by nick205
pop me a u2u reminder and I'll dig out the forum details for you.

Excellent bit of kit (much more practical than the raspberry pi) we use it at work for prototye and test work.


I guess it really depends on the sort of thing you are doing, both are good tools. add a gertboard to a PI and it is very comperant device.

http://www.raspberrypi.org/archives/tag/gertboard

View User's Profile Visit User's Homepage View All Posts By User U2U Member
ChrisW

posted on 26/9/12 at 01:33 PM Reply With Quote
quote:
Originally posted by mad4x4
Try these guys

They have lots of Ardiuno & Rasp PI Stuff SHould have the connector your after


I've used 'those guys' in the past, highly recommended.

Chris





My gaff my rules

View User's Profile E-Mail User Visit User's Homepage View All Posts By User U2U Member
MikeR

posted on 27/9/12 at 11:38 AM Reply With Quote
My summary is the board is broken - decided to fit larger resistors, fitted 4.7k. Still no difference. In a fit of inspiration i removed the I2C leads and got identical results to when i had them connected. Implies that whilst a scan of addresses can find the chips the actual chips aren't working as they should.

Does this sound right to people or could it be something else?

Is it worth trying to power the board by 5v through the 5v connector on the arduino and on the board instead of 3.3v via the 3.3v connectors?
What about with no resistors?

View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 27/9/12 at 12:49 PM Reply With Quote
The I2C bus is most unlikely to work at all without pull-up, they are a rather essential part of the design. Is it possible the sensor PCB has it's own pull-ups on board? I can't seem to find any detailed information on this board, do you have a schematic?

Does the sensor PCB have a voltage regulator on board that will accept 5v? If so, is there any level translation for the I2C bus? You don't want to be putting 5v I2C levels into a chip powered from 3.3v, unless the chip datasheets specifically state this is ok.

The sensor board appears to have a several different I2C devices on the same bus. If all the device correctly ACK their own slave address (which is presumably what the 'address scan' looks for) it seems very unlikely that they are all broken.

What code are you running in the Arduinio to talk to these devices; something you have written or something written by someone else?

View User's Profile View All Posts By User U2U Member
MikeR

posted on 27/9/12 at 09:22 PM Reply With Quote
I don't have a schematic unfortunately.

I don't know for certain about a voltage regulator but it does have a 3.3v pin and a 5v pin so i sort of assume it does.

I think the key bit of the address scan code is this ...

for(address = 0; address <= 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();

if (error == 0)
{
Serial.print("I2C device found at address 0x";
if (address<16)
Serial.print("0";
Serial.print(address,HEX);
Serial.println(" !";

nDevices++;
}
else if (error==4)
{
Serial.print("Unknow error at address 0x";
if (address<16)
Serial.print("0";
Serial.println(address,HEX);
}
}

and I get the following output.
I2C Scanner
Scanning...
I2C device found at address 0x1E !
I2C device found at address 0x53 !
I2C device found at address 0x68 !
I2C device found at address 0x77 !
done

The code I'm trying to use (i've tried a number of libraries and test routines) is the following as its the simplest,

its called adxl345_demo_no_lib, link ....
[Linky Dinky]

This just returns 0's for the attributes x y and z.

View User's Profile View All Posts By User U2U Member
MikeR

posted on 27/9/12 at 10:49 PM Reply With Quote
changed approach. Stuck with 3.3v.

taken some code and added some logging to the serial port which seems to occasionally have some success so now i'm very confused.


Basically every wire action i try to trap the return codes and most of the time I get an ACK fail or a general failure but occasionally i get a '0' indicating success.

Code here ......

#include <Wire.h>


int escapeChar = 101;
int delimiterChar = 100;

void setup()
{
Wire.begin();
Serial.begin(9600); //start serial for output

Serial.println("Starting";
//turning on the ADXL345
writeTo(0x2D, 0);
writeTo(0x2D, 16);
writeTo(0x2D, 8);
}

//Writes val to address register
void writeTo(byte address, byte val)
{
int retcode;
Wire.beginTransmission(0x53); //start transmission to address

if(Wire.write(address) != 1) //send register to address
{
Serial.print(" Failed write address ";
Serial.println(address);
}
if(Wire.write(val) != 1)
{
Serial.print(" Failed to write Val" ; //send value to write
Serial.println(val);
}

retcode = Wire.endTransmission(); //end transmission
Serial.print(" wire.endTransmission returned - ";
Serial.println(retcode);
}

//read bytes
byte readFrom(byte address)
{
int retcode;

Wire.beginTransmission(0x53); //start transmission to device
Wire.write(address); //sends address to read from
retcode = Wire.endTransmission(); //end transmaission
Serial.print(" Send request to read data from address ";
Serial.print(address, HEX);
Serial.print(" return code on request - ";
Serial.print(retcode, HEX);
Serial.print("";

Wire.requestFrom(0x53,1); //request bytes from device

byte temp = Wire.read();
return temp;
}

void loop()
{
char message = Serial.read();

if (message == 'r' {
Serial.println(" ******";
Serial.println(" In main loop ";
slipOut(readFrom(0x32)); //read x lsb
slipOut(readFrom(0x33)); //read x msb
slipOut(readFrom(0x34)); //read y lsb
slipOut(readFrom(0x35)); //read y msb
slipOut(readFrom(0x36)); //read z lsb
slipOut(readFrom(0x37)); //read z msb

Serial.println(" ****** ";
}
}

void slipOut(byte output) //slipout to max/msp
{
if ((output==escapeChar)||(output==delimiterChar))
Serial.println(" SlipOut output is CONTROL_CHAR";
else
{
Serial.print(" Bytes read ";
Serial.print(output, HEX);
Serial.println(" ";
}
}

View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 28/9/12 at 10:11 AM Reply With Quote
Note that Wire.write doesn't do much apart from putting a byte into the transmit buffer, it will always return success unless you try to put too much into the buffer (32 bytes max).

All the hard work is done in the function Wire.endTransmission. What numerical value are you seeing this function return when it fails? (i.e. does it fail to see an ACK when writing the slave address or when writing data?)

I don't see anything blatantly wrong in your code, though when you have 6 registers with consecutive addresses to read it's a big overhead to address the device separately for each byte when you could read all 6 registers in a single operation.

I also don't quite understand the initialisation;

writeTo(0x2D, 0); // Default power on value, device is in standby
writeTo(0x2D, 16); // Set AUTO SLEEP
writeTo(0x2D, 8); // Clear AUTO SLEEP, enable Measure

It looks like first two writes don't actually do anything useful?

Have you kept the wire length between the Arduino and the sensor board as short as possible? Don't twist the I2C wires together either, this increases crosstalk.


EDIT: Have you tried this sketch

[Edited on 28/9/12 by MikeRJ]

View User's Profile View All Posts By User U2U Member
MikeR

posted on 30/9/12 at 08:35 PM Reply With Quote
someone needs to take me outside and explain a few facts to me!!!!!

found the problem - i don't know how to use a prototype board. I hadn't realised that the power rails didn't run all the way down the side of the board. Seems they only run down a little section they're in. Soon as i decided to be stupid and try putting the power to just that section ...... it worked.

In the words of Homer (Simpson), D'oh.

View User's Profile View All Posts By User U2U Member
MikeRJ

posted on 3/10/12 at 11:25 AM Reply With Quote
It depends on the particular boards, some have power rails that run the length of the board (as you'd expect them to!) and some do not. Glad you got it working.
View User's Profile View All Posts By User U2U Member

New Topic New Poll New Reply


go to top






Website design and SEO by Studio Montage

All content © 2001-16 LocostBuilders. Reproduction prohibited
Opinions expressed in public posts are those of the author and do not necessarily represent
the views of other users or any member of the LocostBuilders team.
Running XMB 1.8 Partagium [© 2002 XMB Group] on Apache under CentOS Linux
Founded, built and operated by ChrisW.