1

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)

Onik
  • 19,396
  • 14
  • 68
  • 91
neuberfran
  • 359
  • 3
  • 18

2 Answers2

2

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);
devunwired
  • 62,780
  • 12
  • 127
  • 139
  • 1
    Hi Devunwired, Thanks for answer. When I run i2c-address-scanner (app for AT) I get 0x1B (8 bits address) and not 0x36 (7 bits smartdrive address) In python original driver (https://pastebin.com/6dUYjGY6) it is used 0x36 but in C++ driver it is used 0x1b How to I specify to write-reg-byte if spped value igual 90 (int)? How to I will use writeRegBuffer(int reg, byte[] buffer, int length) and write(byte[] buffer, int length) to pass all parameters at once ???? – neuberfran Jan 22 '18 at 16:37
  • 1
    OpenElectrons_i2c.py https://pastebin.com/TFbtSiWA SmartDrive.py https://pastebin.com/6dUYjGY6 – neuberfran Jan 22 '18 at 22:34
  • 2
    I pulled the default slave address from the datasheet. If you device has a different address then use that one. You can enter values on the CLI in either hex or decimal. – devunwired Jan 23 '18 at 19:15
  • 2
    writeRegBuffer() accepts the register address of the first byte, subsequent values in the array are written into subsequent registers. You're device uses I2C registers, so I can't see why you would want to use raw write() at all. – devunwired Jan 23 '18 at 19:16
  • 1
    Thanks @Devunwired, Based on this: http://nilhcem.com/android-things/arduino-as-an-i2c-slave,Ido this:https://github.com/neuberfran/SmartDrive5 passing as parameters 0x4E and 90 (to speed default of the motor 02) But motor not run. you can see in the log below that the build is ok https://drive.google.com/file/d/1SKZm6OJmS5m8gtr3XsUrv19HYsWjGvNE/view?usp=sharing I still do not know the real need of the ByteExt.KT and why 0XFF. I understood about write() 're 16 bits. On this I will need work with writer(0x02, 0x46, 90.toByte(), durat, C_Wait,,Action_Brake) 0x02 in original drivers= motor 2 – neuberfran Jan 24 '18 at 11:23
  • I said this because this code in c++ used in Android things/jcenter/intel Edison: https://drive.google.com/file/d/1mR5uhAp7_NAj8bwRxScg6WB0yNLvD2IM/view?usp=sharing Pls, Look to: uint8_t ctrl = 0; ctrl |= SmartDrive_CONTROL_SPEED; ctrl |= SmartDrive_CONTROL_TIME; and uint8_t array[5] = {SmartDrive_SPEED_M1, speed, duration, 0, ctrl}; writeArray(array, sizeof(array)); – neuberfran Jan 24 '18 at 11:49
0

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

neuberfran
  • 359
  • 3
  • 18