Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
There are several GPIO pins on the various JST-GH connectors on NavQ. To control these GPIO pins, follow the instructions below.
In order to use GPIO pins, we need to export them in Linux first. To do this, we need to know the GPIO number for the pin we want to access. We can compute this number using the following formula:
For example, if we want to access the GPIO1_IO12
pin on the UART4/I2C/GPIO connector, we would find that the GPIO number is:
If you want to find out what pins correspond to what GPIO numbers, we have tables in the Hardware Overview/Pinouts and Connector
info section here:
Once you know the GPIO number of the pin you want to access, exporting the pin for use is easy. All you have to do is echo the pin number to /sys/class/gpio/export
. For example, if we were to export GPIO1_IO12
, we would run the following in our NavQ console:
Currently we have not created a specific user group to control GPIO pins, so you must be root to export/control pins. If someone in the community would like to submit a process for greating a GPIO user group, please make a post on our hackster.io page and we will add it to the demo image. :)
Next, we will want to change the direction of the GPIO pin for our specific use case. There are two options: in
and out
. To do this for GPIO1_IO12
, you can run the following in your NavQ console:
To read or write a value to the GPIO pin, we will follow a similar process to changing the pin direction. A pseudo file named value
is created at /sys/class/gpio/gpioXXX/value
that holds a 1 or a 0. If you echoed out
to the GPIO direction file, you can control the pin. To control the GPIO1_IO12
pin, just run the following in your NavQ console:
If you echoed in
to the GPIO direction file, you can read the value file and find the current state of the pin. To do this for the GPIO1_IO12 pin, you can run the following in your NavQ console:
Create new group called gpio
2. Create new udev rules file
Create a file at /etc/udev/rules.d/99-gpio.rules and add the following to it:
This will allow you to access the GPIO pseudofiles without being root.
Source code coming soon
There are many communications interfaces supported on NavQ through the JST-GH connectors on the HoverGames Interposer Board. The page links below are guides for each one
[WIP]
This "Project Guide" is written to show some of the capabilites of NavQ. In conjunction with a Teensy LC and a strip of WS2812B LEDs, you can add a forward-facing battery indicator light to your drone.
The software needed to run this project on your NavQ is as follows:
ROS Noetic
MAVROS
You can install this software using the guides here:
The hardware needed is the same as the hardware from the I2C guide here:
At the moment, we're just going to paste the code here, and a more detailed guide will be written later.
This code should be uploaded to the Teensy using the Arduino IDE.
The ROS node should be placed in the home folder ('/home/navq/')
The service file should be located in /etc/systemd/system/.
The Launch script should be located in /usr/local/bin/.
Once all of the necessary files are placed in their respective directories, you need to make the systemd service run at boot. To do this, run in the terminal:
The PWM chips are tied to the onboard LED on NavQ. There are three PWM chips: pwmchip0
, pwmchip1
, and pwmchip2
. Each of these "chips" have one PWM line attached to them: pwm0
. To use these PWM lines, you will need to use the sysfs interface.
Currently, you must be root to access these PWM chips. In the future we will use a udev rules file to change the permissions. This will allow the navq
user to write to the psuedofiles for these chips.
Log into the root
user on NavQ by running this command:
Navigate to /sys/class/pwm and run the following commands:
Now that our PWM lines are exported for each chip, we can change the duty cycle of the PWM lines and enable them. The default frequency is 2730667 Hz. For a 50% duty cycle, we will use half of this number: 1365333. Apply this duty cycle to each chip by running the following commands:
We will now enable each line. The colors for each chip are as follows:
pwmchip0
: RED
pwmchip1
: GREEN
pwmchip2
: BLUE
To enable the colors, run the following commands:
Running these commands in succession should enable the LEDs in a RED, GREEN, BLUE pattern until you reach a white LED.
Comnig soon
A comprehensive guide on using the NavQ as an I2C master (work in progress)
The NavQ includes an I2C port in one of the JST-GH connectors. You may use this port to communicate to other devices in your drone system. In this example, we will go over the process of connecting a Teensy LC to the NavQ over I2C to control some WS2812 LEDs.
Add guide for using C/Python SMBus libraries for controlling I2C
Add more pictures/visuals
Explain teensy code
etc
Teensy LC
JST-GH connectors and pre-terminated wires
Headers
Soldering kit
Teensy side
Arduino IDE
TeensyDuino
NavQ side
i2c-tools (installable from apt)
To create the I2C connector, you'll need to order some JST-GH hardware. Here is a link to a digikey page where you can purchase connectors:
And here is a page where you can purchase the jumpers:
NOTE: For the I2C connector, you'll need the 9-pin JST-GH connector.
In the hardware overview (link here: Hardware Overview), you can see the pinout for the I2C connector. Here is another screenshot of it:
The 5VP pin is on the left-most side of the connector, and GND is on the right-most side. I2C2_SDA is pin 4, and I2C2_SCL is pin 5. The JST-GH connector is positioned with the retention clip facing away from you when you are determining the left/right sides.
You'll need to do some soldering for the first step in this project. In the two pictures below, the NeoPixels are connected to the LED 5V, LED GND, and LED SIG pins. The JST-GH connector to the NavQ connects to the SDA/SCL pins and 5V + GND pads on the back of the Teensy.
Tip: you can solder the pre-terminated JST-GH wires directly to the pads and the through-hole pins to make things easier.
One thing to keep in mind is that even though the Teensy LC does not include pullup resistors to 3.3v for the I2C lines, pullups are not required since the NavQ has internal 4.7k pullups on it's own I2C bus (on the SoM).
Here are a couples images of this setup:
We have written some simple example code that changes the color of the NeoPixel LEDs when the Teensy recieves I2C data. In the example below, the slave address of the Teensy is 0x29, and the color of the LEDs change from green to white when a 0x1 byte is sent to the Teensy. If any other byte is sent to the Teensy, the color changes back to green.
Make sure that you install the Adafruit_NeoPixel library in the Arduino IDE.
The i2c_t3 library is included with the TeensyDuino software. Make sure to use "Wire1" instead of "Wire" since we are using the SDA1/SCLK1 pins on the Teensy.
To use the i2c commands without root, you'll need to add the navq user to the i2c group. To do this, you can run the following command:
Once your Teensy is connected using the I2C JST-GH connector, you need to confirm that the NavQ recognizes the Teensy as an I2C device. To do this, you can run the following command on the NavQ:
You should see a device at address 0x29. If there is no device at address 0x29, you'll need to check your wiring.
To send data to the Teensy, you can use the following command:
This will change the LEDs to white. You can swap the 0x1 with a 0x0 or any other byte to switch back to green.
Controlling the I2C bus with console commands is great, but what about when we want to integrate those commands into code? Well, with Python and C, we can control the Teensy over I2C by using some libraries supplied in both the Linux kernel and through pip.
First, you'll need to install the smbus
pip package. To do this, just run in your terminal:
Once that is installed, you can run a simple script to select a 1 or 0 to send to the NavQ to change the color of the LEDs.
The expected output of this script is as follows:
By selecting 1 or 0, you can change the color of the LEDs to white or green.
To control the I2C bus with C, you can use the following code:
[WIP] A guide on communicating over CAN/SLCAN using NavQ and UCANS32K146
If you're thinking about using the CAN protocol on your drone, this guide will walk you through using our UCANS32K146 to create a CAN interface.
Since there isn't a native CAN bus on the NavQ, we can use a protocol called SLCAN to communicate CAN messages across a UART connection. We have built a binary for the UCANS32K146 that acts as an SLCAN transfer layer. This means that we can add a CAN bus to NavQ by just connecting the UCANS32K146 to the UART3 port.
SLCAN support is enabled in the October image coming out this month.
To enable SLCAN on NavQ, run these commands:
Now you can use SocketCAN or python-can to send and recieve CAN messages over the slcan0 interface. As an example, here is how to send a CAN message from the command line:
This binary is not yet available. This page will be updated with a link to the binary when it is ready.
Follow the guide at the link below to flash the SLCAN binary to your UCAN board: