$ sudo systemctl enable batt_led$ sudo su -
<enter password>$ echo 0 > pwmchip0/export
$ echo 0 > pwmchip1/export
$ echo 0 > pwmchip2/export$ echo 1365333 > pwmchip0/pwm0/duty_cycle
$ echo 1365333 > pwmchip1/pwm0/duty_cycle
$ echo 1365333 > pwmchip2/pwm0/duty_cycle$ echo 1 > pwmchip0/pwm0/enable
$ echo 1 > pwmchip1/pwm0/enable
$ echo 1 > pwmchip2/pwm0/enable
A comprehensive guide on using the NavQ as an I2C master (work in progress)
$ sudo modprobe slcan
$ sudo slcand -o -t sw -s8 /dev/ttymxc2 -S 115200
$ sudo ip link set up slcan0$ cansend slcan0 123#deadbeef#include <Adafruit_NeoPixel.h>
#include <i2c_t3.h>
// MACROS
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 17
#define NUMPIXELS 8
#define DELAYVAL 50
#define SLAVE_ADDRESS 0x29
// INIT PIXELS
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void receiveEvent(size_t bytes);
void requestEvent(void);
// MEMORY
#define MEM_LEN 256
char databuf[MEM_LEN];
volatile uint8_t received;
// INIT VARS
bool latch = false;
bool color = false;
// SETUP I2C AND PIXELS
void setup()
{
Wire1.begin(I2C_SLAVE, 0x29, I2C_PINS_22_23, I2C_PULLUP_EXT, 400000);
received = 0;
memset(databuf, 0, sizeof(databuf));
Wire1.onReceive(receiveEvent);
Wire1.onRequest(requestEvent);
Serial.begin(9600);
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1)
#endif
pixels.begin();
}
// LOOP
void loop()
{
latch = !latch;
for(int i=0; i<NUMPIXELS; i++)
{
if(color)
{
if(latch)
pixels.setPixelColor(i, pixels.Color(5,5,5));
else
pixels.setPixelColor(i, pixels.Color(15,15,15));
}
else
{
if(latch)
pixels.setPixelColor(i, pixels.Color(0,5,0));
else
pixels.setPixelColor(i, pixels.Color(0,15,0));
}
pixels.show();
delay(DELAYVAL);
//Serial.println("loop..");
}
}
// I2C DATA RECV CALLBACK
void receiveEvent(size_t bytes)
{
Wire1.read(databuf, bytes);
if(databuf[0] == 1) color = true;
else color = false;
Serial.println(databuf[0]);
received = bytes;
Serial.println("recv");
}
void requestEvent(void)
{
Wire1.write(databuf, MEM_LEN);
Serial.println("req..");
}$ sudo usermod -aG i2c $USER
$ sudo su
$ echo 'KERNEL=="i2c-[0-9]*", GROUP="i2c"' >> /etc/udev/rules.d/10-local_i2c_group.rules$ i2cdetect -y 1$ i2cset -y 1 0x29 0x1$ pip3 install smbusfrom smbus import SMBus
addr = 0x29
bus = SMBus(1)
numb = 1
print("Enter 1 for WHITE or 0 for GREEN")
while(numb == 1):
ledstate = input(">>>> ")
if(ledstate == "1"):
bus.write_byte(addr, 0x1)
elif(ledstate == "0"):
bus.write_byte(addr, 0x0)
else:
numb = 0navq@imx8mmnavq:~$ python3 i2c.py
Enter 1 for WHITE or 0 for GREEN
>>>> 1
>>>> 0#include <linux/i2c-dev.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <fcntl.h>
int main() {
// Init vars - file descriptor and I2C slave address
int file;
int addr = 0x29;
char filename[20];
// Open the /dev/i2c-1 device filename and apply the address using ioctl
sprintf(filename, "/dev/i2c-1");
file = open(filename, O_RDWR);
if(file < 0) {
printf("Failed to open the i2c bus");
exit(1);
}
if(ioctl(file, I2C_SLAVE, addr) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
exit(1);
}
// Create a data buffer, then ask the user for a 0 or 1 to change LED color
// LED color is changed by writing buf to file
char buf[10] = {0};
buf[0] = 0x0;
while(1==1){
printf("Enter a 0 for GREEN and a 1 for WHITE: ");
scanf("%X", &buf[0]);
if(write(file,buf,1) != 1) {
printf("Failed to write to the i2c bus.\n");
}
printf("\n");
}
}



gpio_number = ((gpio_bank - 1) * 32) + gpio_pingpio_number = ((1 - 1) * 32) + 12
gpio_number = (0) + 12
gpio_number = 12$ sudo echo 12 > /sys/class/gpio/export$ sudo echo in > /sys/class/gpio/gpio12/direction
$ sudo echo out > /sys/class/gpio/gpio12/direction$ sudo echo 0 > /sys/class/gpio/gpio12/value
$ sudo echo 1 > /sys/class/gpio/gpio12/value$ sudo cat /sys/class/gpio/gpio12/value
// a 0 or a 1 should be printed to your console$ sudo groupadd gpio
$ sudo usermod -aG gpio navqSUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"

