Using the i2c smartdrive sensor with a Pio Cli com

2019-08-10 02:40发布

问题:

This is my i2c sensor: http://www.mindsensors.com/rpi/76-smartdrive-high-current-motor-controller look in pdf in Documents sessions please

Based on this google guide https://developer.android.com/things/sdk/pio/pio-cli.html What I need to put in XX ZZ YY UU to run motors in determined speed, direction, duration, etc...

e.g.: pio i2c I2C1 0x1B write-reg-buffer 0xXX 0xYY 0xUU 0xZZ

As (in this case) I will use writeRegBuffer() on my android things app to run one, two or both motors in determined spped, direction, duration, etc?

e.g.: I used (via jcenter) this driver in intel edison/android things DP2, but now I want to create an AT driver to use smartdrive in nx pico and rpi 3, because there would be no more mraa:

https://github.com/androidthings/contrib-drivers/issues/70

My questions is: If you see here: https://github.com/intel-iot-devkit/upm/blob/master/src/smartdrive/smartdrive.hpp and especially in this: https://github.com/intel-iot-devkit/upm/blob/master/src/smartdrive/smartdrive.cxx in function

SmartDrive::Run_Seconds(int motor_id, int direction, uint8_t speed, uint8_t duration, bool wait_for_completion, int next_action )

you will see writeArray(array, sizeof(array));

ok. I need help to use this in android things using writeRegBuffer(int reg, byte[] buffer, int length) and write(byte[] buffer, int length)

回答1:

Per the PIO CLI tool doc you linked, the format of the i2c command is:

$ pio i2c <bus_name> <slave_address> <command> <reg> <val>

Your motor controller has a default slave address of 0x36 and uses registers. As an example you could write to the "Motor 1 Speed" register (address 0x46) using this tool like so:

$ pio i2c I2C1 0x36 write-reg-byte 0x46 <speed_value>

The same operation from code would look like the following:

PeripheralManagerService manager = new PeripheralManagerService();

I2cDevice device = manager.openI2cDevice("I2C1", 0x36);
device.writeRegByte(0x46, speed);


回答2:

run motor 1 in direction A pio i2c I2C1 0x1B write-raw 0x46 128 0x05 0x00 0xD1

run motor 1 in direction B pio i2c I2C1 0x1B write-raw 0x46 127 0x05 0x00 0xD1

run motor 2 in direction A pio i2c I2C1 0x1B write-raw 0x4E 128 0x05 0x00 0xD1

run motor 2 in direction B pio i2c I2C1 0x1B write-raw 0x4E 127 0x05 0x00 0xD1