I'm not sure if this is connected right

I have hooked up the Grove I2C motor driver to an arduino and I’m trying to use the example code but I cant get anything to happen. I;m not sure if I have something hooked up wrong or if it is the code.

This is a picture showing how I have everything hooked up:

picasaweb.google.com/lh/photo/T … directlink

I am currently using the code from the wiki page but I got an error when I tried to compile it that said “call of overloaded ‘write(int)’ is ambiguous” so i had to comment out two lines that said “Wire.write(0);” before the sketch would compile.

All I want is to be able to get two motors to turn forward but so far nothing is happening.

This is the code that I am using, I hope you can help:

#include <Wire.h>

//#define MOTORSHIELDaddr 0x0f
#define SETPWMAB 0x82
#define SETFREQ 0x84
#define CHANGEADDR 0x83
#define CHANNELSET 0xaa
#define MOTOR1 0xa1
#define MOTOR2 0xa5
#define SAVEADDR ‘S’
#define NOTSAVEADDR ‘N’

static unsigned char MOTORSHIELDaddr = 0x28;

void speedAB(unsigned char spda , unsigned char spdb)
{
Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
Wire.write(SETPWMAB); //set pwm header
Wire.write(spda); // send pwma
Wire.write(spdb); // send pwmb
Wire.endTransmission(); // stop transmitting
}

void fre_pre(unsigned char pres)
{
Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
Wire.write(SETFREQ); // set frequence header
Wire.write(pres); // send prescale
// Wire.write(0); // need to send this byte as the third byte(no meaning)
Wire.endTransmission();
}

void change_adr(unsigned char new_adr, unsigned char save_or_not)
{
Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
Wire.write(CHANGEADDR); // change address header
Wire.write(new_adr); // send new address
Wire.write(save_or_not); // save the new address or not
Wire.endTransmission(); //
delayMicroseconds(100); //this command needs at least 6 us
}

void channel(unsigned char i4) //0b 0000 I4 I3 I2 I1
{
delayMicroseconds(4);
Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
Wire.write(CHANNELSET); // channel control header
Wire.write(i4); // send channel control information
//Wire.write(0); // need to send this byte as the third byte(no meaning)
Wire.endTransmission(); //
}
void motorAndspd( unsigned char motor_s,unsigned char Mstatus, unsigned char spd)
{
Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
Wire.write(motor_s); // motor select information
Wire.write(Mstatus); // motor satus information
Wire.write(spd); // motor speed information
Wire.endTransmission(); //
}

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
delayMicroseconds(10); //wait for motor driver to initialization
}

void loop()
{

motorAndspd(0xa1,0b01,225);
motorAndspd(0xa5,0b01,30);
delay(2000);

motorAndspd(0xa5,0b10,225);
motorAndspd(0xa1,0b10,30);
delay(2000);

change_adr(0x12, NOTSAVEADDR );
MOTORSHIELDaddr = 0x12;

for( int i = 0;i< 16;i++)
{
fre_pre(i);
channel(i);
delay(100);
}
speedAB(0 , 0);
change_adr(0x28,NOTSAVEADDR );
MOTORSHIELDaddr = 0x28;

while(1)
{
channel(0b00001010);
delay(500);
channel(0b00000101);
delay(500);
}
}

Dear customer,

Sorry for that, we are not support software, but you can also wait for some other people to help you. :slight_smile:

At one time I had the same error and I corrected it by entering an “int” for that command “wire.write(0)” as such:

int i = 0;
wire.write(i);

Hi all,

The code I was success in Arduino 1.0 IDE.
So what version do you use with?

Thanks everyone, I tried the code using the “int” suggestion and that worked.