0

I'm developing an application to move dc motors, using android things.

At this stage I already know which commands I have to process, but I do not know how. (Using the i2c smartdrive sensor with a Pio Cli commands to run motors)

Below example i2c from guide google developers:

public void writeBuffer (I2cDevice device, byte [] buffer) throws IOException {
     int count = device.write (buffer, buffer.length);
     Log.d (TAG, "Wrote" + count + "bytes over I2C.");
}

My question (based on the code above) is:

1) How to write (in Kotlin) pio i2c I2C1 0x1B write-raw 0x46 128 0x05 0x00 0xD1 in buffer to pass as parameter in writeBuffer function?

e.g.: var buffer = (new byte[] (byte) 0x46, 128, 0x05, 0x00, 0xD1, value.i2cValue.toByteArray()), did not work.

My final project is based on the project below: https://github.com/Nilhcem/i2cfun-androidthings/tree/arduino_slave/app/src/main/java/com/nilhcem/androidthings/i2cfun

quote: I know that I2C1 and 0x1B are not required because they are passed parameters, either before, or in I2cDevice.

neuberfran
  • 359
  • 3
  • 18
  • 1
    `var buffer = (new byte[]...` is not quite Kotlin – Onik Jun 30 '18 at 11:36
  • 1
    Not really an answer, but there are very simple dc motor controllers (such as L298N) that work using 4 GPIO pins and there's plenty of examples online and even some drivers. – shalafi Jun 30 '18 at 17:56
  • Hi, tks, but I stay working with two car windshield motors/rpi3/smartdrive-i2c-driver. Bridge H L298N not support the amperage of the motors and my power supply switched of the 12v and 20A – neuberfran Jun 30 '18 at 23:33
  • 1
    I solved this issue: https://drive.google.com/file/d/1i_selEXwqWM5tQN7KPcqWd35Di_avNTa/view?usp=sharing but now I have issue with PeripheralManager in Preview 7 A Things: https://drive.google.com/file/d/1A3IQmnIQ7BodDonbIeVVXyjlAF3tOYnH/view?usp=sharing https://drive.google.com/file/d/1htJCNt--1iJtrIMkVLgT3XIETUjKQU_1/view?usp=sharing https://stackoverflow.com/questions/49141634/peripheralmanagerservice-throws-noclassdeffounderror – neuberfran Jul 02 '18 at 14:36
  • @NEUBERSOUSA If you've solved the issue, please post how you solved it. If you have any other questions. Please create a new question. – OrhanC1 Jul 02 '18 at 14:49
  • 1
    I solved: val buffer = byteArrayOf(0x46, 128.toByte(), 0x05, 0x00, 0xD1.toByte()) and device?.write(buffer, buffer.size) – neuberfran Jul 02 '18 at 14:55

1 Answers1

0

I solved: val buffer = byteArrayOf(0x46, 128.toByte(), 0x05, 0x00, 0xD1.toByte()) and device?.write(buffer, buffer.size)

neuberfran
  • 359
  • 3
  • 18