raspberry-sharp / raspberry-sharp-io

A .NET/Mono IO Library for Raspberry Pi
339 stars 139 forks source link

Can't get I2C to work #49

Open Senna-chan opened 9 years ago

Senna-chan commented 9 years ago

I am trying to connect to the Adafruit Motor hat(that uses the Adafruit PWM code), but the code can't find a I2C device

Error

System.InvalidOperationException: No I2C device exist on the specified pins
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver.GetBscBase (ProcessorPin sdaPin, ProcessorPin sclPin) [0x000a5] in <filename unknown>:0
  at Raspberry.IO.InterIntegratedCircuit.I2cDriver..ctor (ProcessorPin sdaPin, ProcessorPin sclPin) [0x00020] in <filename unknown>:0
  at motorTest.Motor_Hat..ctor (Int32 addr, Int32 freq) [0x00081] in /home/pi/motorTest/motorTest/adafruit_ports/Motor_Hat.cs:42
  at motorTest.MainClass.Main (System.String[] args) [0x00008] in /home/pi/motorTest/motorTest/Program.cs:9

Motor_Hat.cs(Relevant code)

public Motor_Hat(int addr, int freq = 1600){
    _i2caddr = addr;           
    _frequency = freq;          
    for(int i=1;i<5;i++){
        motors.Add (new DC_Motor (this, i));
    }
    steppers.Add (new Stepper_Motor (this, 1));
    steppers.Add (new Stepper_Motor (this, 2));
    var I2CDriver = new I2cDriver (ProcessorPin.Pin03, ProcessorPin.Pin05);
    _pwm = new Pca9685Connection (I2CDriver.Connect(addr));
    _pwm.SetPwmUpdateRate(_frequency);
    }

Am I doing anything wrong? The hat does work with the python code.

Senna-chan commented 9 years ago

After looking in the tests I found a example-code for the PCA9685. I will try to look if I can use the test and to possibly port the motorhat code to the raspberry-sharp-io library.