Android communications

Started by Tinine, July 01, 2023, 16:44:33

Previous topic - Next topic

chrisws

Should have also mentioned: the jar holds my compiled java code as well as the ioio-otg and jtermios libraries.

J7M

Would be great, if you can provide this file.

I had the same problem. After first plugin the board to USB it showed up as a serial interface but I couldn't connect. After playing around and plug/unplug several times it suddenly worked. I will check if it was the "playing around" or the unpluging which got it working.


J7M

Thanks for the file. Now I can control the board using SB. But there seems to be an USB connection bug. I need to plug/unplug several times the USB cable until I get a connection. I have to execute the IOIO example program HelloConsole...jar for connecting the first time. When this program reports "connection established" I can quit it and use SB. Without using HelleConsole.jar SB will never connect. It always got stuck at "waiting for handshake".
After a while of playing around, I got annoyed with plug/unplug the USB cable. I found a nice hack to reset the board. Just connect the "mclr"-pin (top left of the board) with a push button to ground and the board resets. I start HelloConsole.jar and press the push button several times until the program reports that it established a connection.

chrisws

That was pretty much my experience as well. There are also ioio.reset() and ioio.hardReset() functions. I wonder if these could be used instread of the hardware button?

I'm not sure what's special about HelloConsole - I'll look into this a bit more as well.

I raised this last year but so far no has answered: https://github.com/ytai/ioio/issues/356 

chrisws

I managed to get my Ambient Light Sensor device (VEML6030) working using the TwiMaster module (i2c).

Next to try is a BME280 which is a bit more complicated, so probably need to refactor a few things.

code is here: https://github.com/smallbasic/smallbasic.plugins/tree/master/ioio

All so entertaining.

chrisws

#36
My bme280 device is now working, in part thanks to some scary python code that I converted to even scarier looking SmallBASIC :)

The device has various calibration parameters that need to be read at startup. These are used with the raw data feed to calculate the temperative, humidity and pressure.

The temperature readings are consistent with my thermometer, so at least is giving the appearance of working.

Also... I solved the "waiting for handshare" issue by switching over to a different java library for dealing with the serial port. Could have saved some headaches fixing that at the start.


J7M

That sounds good. I'll also try to get some sensors running.

chrisws

I started working on the android integration of the ioio project.

I have this idea for making a robot. 

- buy a 'smart' robot kit and replace any control module with the IOIO board.
- strap an android phone to the robot.
- add some support for calling an LLM api (chatgpt or claude etc).
- give the LLM instructions on how to read sensors, control any motors or give feedback.
- this would all be tied together with an SmallBASIC program.
- let it wonder around the house and play with the cats.

I asked claude about this and he/it was pretty excited! 

Tinine

Quote from: chrisws on March 11, 2024, 09:57:14I started working on the android integration of the ioio project.

I have this idea for making a robot.

- buy a 'smart' robot kit and replace any control module with the IOIO board.
- strap an android phone to the robot.
- add some support for calling an LLM api (chatgpt or claude etc).
- give the LLM instructions on how to read sensors, control any motors or give feedback.
- this would all be tied together with an SmallBASIC program.
- let it wonder around the house and play with the cats.

I asked claude about this and he/it was pretty excited!

Exactly  8)

We actually begin with a kick-butt HMI that has processing power, GPU, memory, BT. WiFi, touchscreen, etc and able to control external hardware.

Exciting times  :D


chrisws

It's basically working on android now. I got blinking a led!

I'm using the same codebase as the "PC" version in the modules repository. This builds an android archive file (aar) which can then be included in the Android version of SmallBASIC via a configuration setting. There's just a few general changes to the SB android code to handle "modules".

Handling the USB permission still isn't quite right. Then next I'll need to figure out how "on demand delivery" works, or maybe just share a different version in some other way.

Tinine

I'm like a kid at Xmas, here. Android-based CNC anyone?

I have developed the motion stuff - not mickey-mouse stepper motors but true closed-loop servo-motor stuff. Lots of people frustrated with LinuxCNC and Mach-4. I'd need help with the front-end UI, etc. but we could kick some butt with this combo  8) ;D


J7M

I was able to build the newest ioio-plugin for the PC. This time I could connect to the ioio-board without any problems. Nice work :)  The next weeks I have more time to have a closer look to ioio. I will also try the Android implementation. But first I need to do some soldering. My board doesn't have any pins...

J7M

Hi Chris, maybe you can help. I tested the board and stuck with I2C. I followed your example of BME280 and was able the get a BH1750 working. Additionally I tried a MPU6050, SCD30 and SSD1306. All of them don't follow the way you implemented the functions write and readwrite. You don't have a register and write data to that register or read data from there. For them usually you just send a command (in case of SDC30 and SSD1306, these commands are 16bit). Here is an example for the SSD1306. I can initialize the display by using the write function in a not-intended-way. Maybe I missed something and I'm using the functions wrong.

import ioio

const ADDRESS = 0x3C
const WIDTH = 128
const HEIGHT = 64

Print "Connect to SSD1306 oled display"
oled = ioio.openTwiMaster(0, 0)
ioio.waitForConnect(10)
Print "Connection established"

delay(500)

' Init sequence according to specsheet
' Display off
SendCommand(0xAE)
' Set Multiplex Ratio
SendCommand(0xA8)
SendCommand(SSD1306_LCDHEIGHT - 1)
' Display Offset
SendCommand(0xD3)
SendCommand(0x0)
' Set Display Clock Divide Ratio / Oscillator Frequency; suggested ratio 0x80
SendCommand(0xD5)
SendCommand(0x80)
' Display Start Line -> 0
SendCommand(0x40)
' Set Segment Re-map: column address 127 is mapped to SEG0
SendCommand(0xA1)
' Set COM Output Scan Direction: remapped mode. Scan from COM[N-1] to COM0
SendCommand(0xC8)
' Set COM Pins Hardware Configuration
' Alternative COM pin configuration + Disable COM Left/Right remap
SendCommand(0xDA)
SendCommand(0x12)
' Set Contrast Control (Brightness)
' 0 to 255
SendCommand(0x81)
SendCommand(200)
' Entire Display ON: A4h command enable display outputs according to the GDDRAM contents
SendCommand(0xA4)
' Set Normal Display: This command sets the display to be either normal or inverse.
' In normal display a RAM data of 1 indicates an  "ON" pixel while in inverse display
' a RAM data of 0 indicates an "ON" pixel
' 0xA6 normal, 0xA7 invers
SendCommand(0xA6)   ' <- for testing set to invers. The display should be white.
' Charge Pump Setting
' Enable Charge Pump
SendCommand(0x8D)
SendCommand(0x14)
' Memory Addressing Mode
' Horizontal Addressing Mode
SendCommand(0x20)
SendCommand(0x00)
' turn on display
SendCommand(0xAF)

' Setup framebuffer
dim FrameBuffer(WIDTH * HEIGHT / 8)
for ii = 1 to WIDTH * HEIGHT / 8
    FrameBuffer[ii] = 255  ' all 8 pixels are white
next

'Send 0x40 for update RAM followed by the framebuffer data
'oled.write(ADDRESS, 0x40, 255) ' this shows 8 white pixels on the display

'oled.write(ADDRESS, 0x40, FrameBuffer) ' doesn't work

'oled.write(ADDRESS, 0x40) ' combination doesn't work
'oled.write(ADDRESS, FrameBuffer)

sub SendCommand(c)
    'dim buffer(1)
    'buffer[0] = 0  
    'buffer[1] = c   
   
    oled.write(ADDRESS, 0, c)  '<- this works
   
    'this should work but doesn't
    'oled.write(ADDRESS, 0)
    'oled.write(ADDRESS, c)
   
    'this should also work but doesn't
    'oled.write(ADDRESS, [0,c])
    'or
    'oled.write(ADDRESS, buffer, length? )
end
' C code for sending a command.
' void SSD1306_Command(char command)
'{
'    char input_buffer[2];
'
'    input_buffer[0] = 0x00;
'    input_buffer[1] = command;
'
'    i2cWriteDevice(ssd1306, input_buffer, 2);
'}

Can you have a look to veml6030.bas:

* COMP-ERROR AT Main:37 *
Description:
Array: Missing ')', (left side of expression)