Need Help in Connecting Computer and arduino using USB-I2C connector

hi all,

I have been trying to develop master and slave connection between Computer and Arduino using I2c bus......I have a USB-I2C converter which i used for connecting my computer with arduino.....and trying to drive a SERVO motor.

I developed the following code but it is not working.......i dont know where i made mistake .... i am producing my code below if there is any mistake please help me out .....Thanks in advance

My Computer code (Master)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;

namespace MasterComputer_I2C
{
class Program
{
static void Main()
{
// initialize port
SerialPort serial = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.Two);
//open port
serial.Open();
//Data --> address= 1+R(0)
serial.Write(new byte[] { 0x53, 0x01,0x01,0x00,0x50}, 0, 5);
//close port
serial.Close();
}
}
}

Arduino Code:

#include <Wire.h>
#include <Servo.h>

Servo servo;

void setup()
{
Wire.begin(1);
Wire.onReceive(receiving);
servo.attach(9);
}
void loop()
{}

void receiving(int)
{
int x = Wire.receive();
servo.write(x);
}

Can anyone help me out pls........

Thanks again

I have a USB-I2C converter

Which one?

            serial.Write(new byte[] { 0x53, 0x01,0x01,0x00,0x50}, 0, 5);

You are sending 5 bytes, and expecting one. Why? What are the other 4 values for?

hi paul,

The model i use has a addressing format of ( 'S' char , dev add+R/W , no.of bytes, DATA, 'P' char)

S - start bit
P- Stop bit

i read that this is the method for sending data to the slave.... i learnt this from the following link (pdf) http://www.web4robot.com/files/USBtoI2C.pdf.....

The serial data format is: one start bit, 8 data bits, and one stop bit. The baud rate is 9600 bit/s.

            SerialPort serial = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.Two);

It would be strange for the value of the property StopBits.Two to be one, wouldn't it?

I don't think 19200 equals 9600, either.

How is the device connected to the Arduino?

hi paul

The arduino is connected through I2C and the Computer through USB....... The USB to I2C convertor is used in between......Regarding Baud Rate i took that information from USB-I2C Communications Module.....

The arduino is connected through I2C

This doesn't mean squat. What pins on your device are connected to what pins on the Arduino?

Regarding Baud Rate i took that information from

Why didn't you use the information for your device?

hi paul

The device i am using is pictured in the link USB-I2C Communications Module ..which i already send....It has the pin details and serial communication parameters..... am i thinking right about this communication method???? ...Do i miss some basics here??

Thanks for replying .....

It has the pin details and serial communication parameters.

I will not assume that you have connected it correctly. Please describe how you have connected it to your Arduino.

You are not using the serial communications parameters from that link. You are using stuff you got from somewhere else for some other device. It's no wonder they can't communicate.

hi paul

Connection details

USB-I2C interface pin 5volts --------> arduino pin Vin
USB-I2C interface pin GND --------> arduino pin GND
USB-I2C interface pin SDA --------> arduino pin 4
USB-I2C interface pin SCL --------> arduino pin 5
USB-I2C interface pin Input --------> left out

Is the format for I2C data transfer wrong??...If yes what format should i use

Thanks

USB-I2C interface pin SDA --------> arduino pin 4
USB-I2C interface pin SCL --------> arduino pin 5

The Arduino has digital pins 4 and 5, and analog pins 4 and 5. Which are you connected to?

Is the format for I2C data transfer wrong?

Hardly. It's all controlled by a library.

Your code for the PC to talk to the device appears to be wrong, though.

hi paul

The i2c is connected to arduino analog pins 4 and 5(A4 - SDA , A5 - SCL)

can you specify what's wrong in PC code..... Because i am unable to find it.....

Thanks

Because i am unable to find it.....

Look at reply # 3.

hi paul

I have the changed the baud rate to 9600 ...Even though i am unable to communicate with arduino.......I have some doubt in the method of sending data thorugh I2C..... ( i.e) serial.Write(new byte[] { 0x53, 0x40, 0x01, 0xB4, 0x50}, 0, 5);

here 0x53 ==> 's' - char (start bit)
0x40 ==> address of slave
0x01 ==> No.of bytes
0xB4 ==> data ( 180 in decimal for running servo)
0x50 ==> 'p' - char (Stop bit)

Am i right in this or did i made any mistake??? i need your guidance

Thanks for replying

Hi karthickdharma1987:
Did you solve the communication?. I'm trying too but NOTHING.

Regards.