Ashfaque Ahmed Khan
Ashfaque Ahmed Khan

Reputation: 13

Unable Initialize I2C Pins on Pico RP2040 for AS5601 Library using Earlphilhower's Arduino-Pico

I am using Earlphilhower's Arduino-Pico, and this AS5601 library for testing my AS5601 breakout board. Below is the sample code I am running:

#include "Arduino.h"
#include "AS5601.h"

AS5601 Sensor;

void setup()
{
    Wire.begin();
    delay( 1000 );
    Serial.begin( 115200 );
    Serial.println( F("Angle Measurement with AS5601") );
}

void loop()
{
    Serial.print( F("Magnitude: ") );
    Serial.print( Sensor.getMagnitude() );

    Serial.print( F(" | Raw angle: ") );
    Serial.print( Sensor.getRawAngle() );

    Serial.print( F(" | Clean angle: ") );
    Serial.print( Sensor.getAngle() );

    if ( Serial.read() == '0' )
    {
        Sensor.setZeroPosition();
        Serial.print( F(" | Zero position set!") );
    }

    Serial.println();

    delay( 50 );
}

but I am unbale to read anything from the sensor, but this whole setup works for my teesny 3.5 I understand that there is some issue in initializing the I2C pins for Pico but after searching on internet I was unable to figure it out, please help me.

I searched thoroughly on internet, but was unable to figure it out.

I tried setting the sda and scl pin in the AS%601.h lib file:

            wireChannel = &Wire;
            wireChannel->setSCL(5);
            wireChannel->setSDA(4);
            wireChannel->begin();

like this but it didnt worked, and also when I did this the board was not being detected in my pc, whenever I run this code this happens, like whenever I set those pin declaration.

Please help me to initialize the i2c properly in my Pico RP2040 so that I can use the AS5601.

Upvotes: 1

Views: 100

Answers (1)

Ashfaque Khan
Ashfaque Khan

Reputation: 66

void loop() {
  Wire.beginTransmission(AS5600_AS5601_DEV_ADDRESS);
  Wire.write(AS5600_AS5601_REG_RAW_ANGLE);
  Wire.endTransmission(false);
  Wire.requestFrom(AS5600_AS5601_DEV_ADDRESS, 2);
  uint16_t RawAngle = 0;
  RawAngle  = ((uint16_t)Wire.read() << 8) & 0x0F00;
  RawAngle |= (uint16_t)Wire.read();

  Wire.beginTransmission(AS5600_AS5601_DEV_ADDRESS);
  Wire.write(AS5600_AS5601_REG_ANGLE);
  Wire.endTransmission(false);
  Wire.requestFrom(AS5600_AS5601_DEV_ADDRESS, 2);
  uint16_t Angle = 0;
  Angle  = ((uint16_t)Wire.read() << 8) & 0x0F00;
  Angle |= (uint16_t)Wire.read();

  Serial.print(RawAngle);
  Serial.print(",");
  Serial.println(Angle);

try running this , i just used the regs directly

Upvotes: 1

Related Questions