Hi all,
i’m using the function writeByte in the MB85RC04 driver code to communicate with a Flora Arduino Board over the I2C bus. the purpose of my program is to control a LED ring (a NeoPixel Ring from Adafruit) connected to the Arduino Board.
LEDs are expected to change color depending on the data sent on the I2C bus. (the final purpose is for example to display red LEDs when i swith to the RTH mode. blue LEDs for the MANUAL mode etc.)
here is my code
FLORA.h
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include "I2Cdev.h"
class FLORA
{
public:
uint8_t device_address;
FLORA(uint8_t address = 0b101010); //0x2a the address of the Arduino board
uint8_t readByte(uint8_t* data);
uint8_t writeByte(uint8_t data);
uint8_t readBytes(uint8_t length, uint8_t* data);
uint8_t writeBytes(uint8_t length, uint8_t* data);
};
FLORA.cpp
#include "FLORA.h"
FLORA::FLORA(uint8_t address)
{
this->device_address = address;
}
uint8_t FLORA::readByte(uint8_t* data)
{
return I2Cdev::readByte(device_address, 0x0, data);
}
uint8_t FLORA::writeByte(uint8_t data)
{
return I2Cdev::writeByte(device_address, 0x0, data);
}
uint8_t FLORA::writeBytes(uint8_t length, uint8_t* data)
{
return I2Cdev::writeBytes(device_address, 0x0, length, data);
}
uint8_t FLORA::readBytes(uint8_t length, uint8_t* data)
{
return I2Cdev::readBytes(device_address, 0x0, length, data);
}
`
and the main program FLORA_test.cpp
#include <stdio.h>
#include <unistd.h>
#include "Navio/I2Cdev.h"
#include "Navio/FLORA.h"
int main()
{
FLORA flora;
uint8_t dev_address = flora.device_address;
uint16_t reg_address = 0;
// multiple write and read functionality test
printf("Multiple read/write functionality test!\nWe will write values 'x' 'y' 'w' 'v' 'u' 't' and 's'\nto the addresses of flora: 0x%x\n",dev_address);
uint8_t data[7] = {'x', 'y', 'w', 'v', 'u', 't', 's'};
printf("\nWriting data...\n");
while(true) {
for (int i=0; i<7; i++) {
printf("\n\nWriting %c", data[i]);
flora.writeByte(data[i]);
sleep(1);
}
}
return 0;
}
the program returns no error but nothing happens on the Arduino Board.
i check the I2C bus and i see the address of the Arduino 0x2a
$
$ll /dev/i2c*
crw-rw---T 1 root i2c 89, 1 Dec 30 00:17 /dev/i2c-1
$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- 19 -- UU -- -- 1e --
20: -- -- -- -- -- -- -- -- -- -- 2a -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77`
here are the photo of my Rover