Example programs for ArduinoPixed

October 8th, 2018

ArduinoPixed adds 3 USB ports and an onboard Arduino. Setting up Arduinopixed is easy. Just use the 4 provided screws to attach it to Raspberry Pi Zero W ( Add a USB Wifi Board if you are using Raspberry Pi Zero). The Extra USB ports on the Arduinopixed allows you to work directly on the Raspberry Pi - No SSH or Serial Port required ( but you can do that if you want to). Hook the Pi Zero to HDTV using HDMI to HDMI Mini Cable. Hook a Keyboard and Mouse to the USB Ports of the Arduinopixed.

After powering it on - set up your wifi.

Install the Arduino using

#sudo apt-get install arduino

Now you should be able to run the Arduino from the menu. Here are some example programs to get you started.

Example : LED Blinking

This example will blink and LED for 1 sec and off for 0.2 second on the Arduinopixed. Note that the LED is connected on Pin 6 in place of 13 in Arduino or Arduino Nano.

void setup() {
pinMode(6, OUTPUT);

void loop() {
digitalWrite(6, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(6, LOW); // turn the LED off by making the voltage LOW
delay(200); // wait for a second

Example : LED ON off on Push button

The example will turn on or off the LED on Arduoinopixed depending upon if the the Push Button is pressed or not. The push button is connected on Pin 7 and is normally high. When the Push Button is pressed, it turns low.

const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin = 6; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);

Example : A/D Converter that throws Sensed value at Serial Port every 500 ms

const int analogInPin = A7; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 6; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.print("\t output = ");

//500 ms wait


USB Wifi on Freescale i.MX6

April 12th, 2018

This post is about how to get the USB wifi working. The TP-Link TL-WN721N wifi Module has been used as an example but it should be possible to extend similar thing on other Wifi Modules as well.

1. In the kernel Select the Athroes HTC as module and build the kernel module.
2. Copy the generated four files - ath.ko, ath9k_hw.ko, ath9k_common.ko and ath9k_htc.ko in directory /system/lib/modules/
3. Copy the firmware file in the directory /etc/firmware/ath9k_htc/
4. Install the modules using ath.ko, ath9k_hw.ko, ath9k_common.ko
5. ifconfig wlan0 up
6. iw dev wlano scan
7. To connect to a network that does not need password use
iw wlan0 connect yourssid
8. use wpa_supplicant to connect to network that needs authentication


Order ArduinoPixed

March 19th, 2018

ArduinoPixed has been ranked 9 out of 10 in March 2019 issue of MagPi - https://www.raspberrypi.org/magpi/arduinopixed-review/

If you missed backing ArduinoPixed on kickstarter here is a chance order .

ArduinoPixed - USB Hub + Arduino for Pi Zero
ArduinoPixed - USB Hub + Arduino for Pi Zero
Hub + Arduino for Pi Zero W , Shipping is $5 in US

Out of US : The shipping is $6 for first and $3 for each additional unit.

HubSerialixed - USB Hub + UART for Pi Zero
HubSerialixed - USB Hub + UART for Pi Zero
Hub + UART for Raspberry Pi Zero, Shipping is $7 out US


Spread Spectrum in i.mx6

March 14th, 2018

If the CPU to DDR clock fails due to the EMI, there is a quick software solution - Spread Spectrum. The changes can be made in the u-boot. You will need to create the u-boot in SPL mode. Add the following code ( located at board/freescale/mx6sabresd/).

#include <config.h>

/* Enable Spread Spectrum */
.macro spreadspectrum_vikas
ldr r0, =CCM_BASE_ADDR

ldr r1, [r0,#0x18]
ldr r3, [r0,#0x18]

/*need Delay short time before switch PLL2 it back*/

ldr r4, =0x0
add r4, r4, #0x1
cmp r4, #0x200000
bne pu_delay

/* recovery the previous PLL source setting */
ldr r0, =CCM_BASE_ADDR
str r3, [r0,#0x18]

.macro spreadspectrum_rohitab
ldr r0, =CCM_BASE_ADDR

ldr r1, [r0,#0x18]
ldr r3, [r0,#0x18]

/* set periph_clik2_sel to select OSC_CLK */
and r1, r1, #0xffffcfff
orr r1, r1, #0x00001000
str r1, [r0,#0x18]

/*need Delay short time before switch PLL2 it back*/
ldr r4, =0x0
add r4, r4, #0x1
cmp r4, #0x200000
bne pu_delay

/* recovery the previous PLL source setting */
ldr r0, =CCM_BASE_ADDR
str r3, [r0,#0x18]

.macro spreadspectrum
ldr r0, =CCM_BASE_ADDR

ldr r1, [r0,#0x18]
ldr r3, [r0,#0x18]

/* set periph_clik2_sel to select OSC_CLK */
and r1, r1, #0xffffcfff
orr r1, r1, #0x00001000
str r1, [r0,#0x18]

/* set periph_clk_set to switch to OSC_CLK */
ldr r1, [r0,#0x14]
ldr r2, [r0,#0x14]
orr r1, r1, #0x02000000
str r1, [r0,#0x14]

/* power down PLL2 */
ldr r0, =0x020c8000
ldr r1, [r0,#0x30]
orr r1, r1, #0x00010000
str r1, [r0,#0x30]

/* enable spread spectrum & configure */
ldr r1, =0x00001770
str r1, [r0,#0x60]
ldr r1, =0x05dc8006
str r1, [r0,#0x40]

ldr r1, [r0,#0x30]
and r1, r1, #0xFFFEFFFF
str r1, [r0,#0x30]

/*need Delay short time before switch PLL2 it back*/
ldr r4, =0x0
add r4, r4, #0x1
cmp r4, #0x200000
bne pu_delay

/* recovery the previous PLL source setting */
ldr r0, =CCM_BASE_ADDR
str r2, [r0,#0x14]
str r3, [r0,#0x18]


/* End Enable Spread Spectrum */

.globl blhss
.type blhss,%function

bx lr

Save the file as spreadspectrum.S and then update the Make file to include this file.

obj-y := mx6sabresd.o
obj-y += spreadspectrum.o

In file mx6sabresd.c make following changes

  1. Just before

int dram_init(void);


extern int blhss(void);

2. Just after


Add following



Compile and try. Results will be updated lated.


Preparing i.MX6 to boot from SD Card

March 9th, 2018

Let us assume that you have compiled the u-boot for freescale/nxp i.MX6 and are now trying to prepare the SD Card to boot the i.MX6 from it.

Before you do that, you need to make sure your hardware is ready for it. The i.MX6 should not have been fused to prevent it from booting from external SD Card. Also the Config Pins should be properly set, so that it can boot from SD Card ( and not from SPI Flash as in Sabre Lite Board).

Once you do that, all you need to do is just burn an SD Card with the following command.

sudo dd if=some/directory/u-boot.imx of=/dev/sdb bs=1k seek=1 conv=fsync

It is good idea to spend some time on to understand the bs and the seek parameter in the command. The bs is block size and in our case it is 1K or 1024 bytes. The seek parameter is a pointer on the SD Card. If we set seek to 1, it will move forward by 1 block size on the SD Card before write.

If your u-boot.imx file, for example, already has padded 0s in the beginning, you do not need the bs=1k seek=1

Why Do we need u-boot start from 1K ( 0x0400) ?

This requirement comes from i.MX6. The i.MX6 will look at the address 1024 to load the data into its ROM and execute from there. Notice that at this point we have not created any partition whatsoever and the board will still boot. The u-boot does not care about the Master Boot Record. Though we will need some kid of partition information information to read file system later in the boot process.

A typical SD Card with MBR partition will look as follows ...


| MBR | ... | u-boot | ... | Partition1 |...Partition2 |...Partition3


0 512 1024 2M 20M 100MB

The Master Boot Record is stored in the first 512 Bytes of the SD Card. This contains the details of the partition of the SD Card. With all its limitations ( number of partitions it can store etc), the MBR works good. Though, we do not need it for the very first boot from u-boot of i.MX6.

Now you understand why i.MX6 was not designed to boot from the address 1K Byte in place of 0x0000. If it were designed to boot from 0x0000, we will be writing the u-boot right at 0x0000 - and it will then destroy the MBR.


GPT (GUID Partition Table) brings with it many advantages, including support for bigger cards / disks and ability to store larger partition tables. The GPT starts at location 512 Bytes and a typical scenario looks like


| |GPT | u-boot | ... | Partition1 |...Partition2 |...Partition3


0 512 1024 2M 20M 100MB

With reference to u-boot, the scheme still works, with one caveat - the GPT partition table can extend ( because it is large) to the u-boot area that starts at 1024 Bytes. So if you create the GPT first and then write the u-boot, the u-boot writing process will destroy the GPT Table ( at least partially, unless it is really small). If you write u-boot first and then create GPT, the GPT creation process will destroy the u-boot.

So is there a solution ? Fortunately Yes. The GPT allows relocation of the Partition table. What we basically do is create an entry in the first few bytes of the GPT Table that tells where the rest of Table is going to be. We can then reserve some other place in the boot partition to store the GPT Table.


Cheat Sheet installing Android 7.1.2 nouget on i.mx6

March 6th, 2018

It has been a while since Freescale released nouget 7.1.2. We have clubbed together a cheat sheet to build Android for the Sabre SD platform. This should help you to do a quick copy paste to get whole thing going.

Install following packages

It is possible that you have following packages already installed - but just make sure

sudo apt-get install uuid uuid-dev
sudo apt-get install zlib1g-dev liblz-dev
sudo apt-get install liblzo2-2 liblzo2-dev
sudo apt-get install lzop
sudo apt-get install git-core curl
sudo apt-get install u-boot-tools
sudo apt-get install mtd-utils
sudo apt-get install android-tools-fsutils
sudo apt-get install openjdk-8-jdk

Create a directory - call it myandroid to hold all the packages

$ cd ~
$ mkdir myandroid
$ mkdir bin
$ cd myandroid
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ ~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r9
$ ~/bin/repo sync
# Please make sure you have plenty of time. It may take overnight.
$cd ~/myandroid/system/tools
$ git clone https://android.googlesource.com/platform/system/tools/bpt
$ cd bpt
$ git checkout -b n7.1.2_2.0.0-gab7c3059e5d8c408f60222edc898ef1c229d8fc2d

No Get the kernel source code

$cd ~/myandroid
$git clone git://git.freescale.com/imx/linux-imx.git kernel_imx
#the kernel repo is large. Therefore, this process can take a while.
cd kernel_imx
$git checkout n7.1.2_2.0.0-ga

Get the u-boot

$cd ~/myandroid/bootable
$mkdir bootloader
$cd bootloader
$git clone git://git.freescale.com/imx/uboot-imx.git uboot-imx
$cd uboot-imx
$git checkout n7.1.2_2.0.0-ga

Download the file android_N7.1.2_2.0.0_source.tar.gz from nxp / freescale ( requires login) to directory, say, android7.1.2 and unzip it

$cd android7.1.2
$tar xzvf android_N7.1.2_2.0.0_source.tar.gz

$cd ~/myandroid
$source ~/android7.1.2/android_N7.1.2_2.0.0_source/code/N7.1.2_2.0.0/and_patch.sh
Make sure you see a c_patch command available
$c_patch ~/android7.1.2/android_N7.1.2_2.0.0_source/code/N7.1.2_2.0.0/ imx_N7.1.2_2.0.0-ga

If this is successful you should see a message that says something like - you can build the Android code for FSL.

Building Android

$cd ~/myandroid
$source build/envsetup.sh

Select sabresd_6dq-user

The following is required to avoid GC overhead limit error. Increasing heap size helps.

$export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
$./prebuilts/sdk/tools/jack-admin kill-server
$./prebuilts/sdk/tools/jack-admin start-server

Not the make command

$ make 2>&1 | tee build-log.txt

It takes some time ( Like 5 hours of a decent laptop).

The above process generates files for eMMC. To generate it for SD Card, you will need to do following

1. Remove /out/target/product/sabresd_6dq/root directory and boot*.img.
2. Remove /out/target/product/sabresd_6dq/recovery directory and recovery*.img.
3. Build the boot.img and recovery.img as follows:
make bootimage BUILD_TARGET_DEVICE=sd
make recoveryimage BUILD_TARGET_DEVICE=sd

To create SD Card to boot

$cd ~/myandroid/
$sudo chmod +x ./device/fsl/common/tools/fsl-sdcard-partition.sh
$sudo ./device/fsl/common/tools/fsl-sdcard-partition.sh -f /dev/sdX
can is imx6q I.MX6 quad processor

Keep all the required files in the current directory.

Issues and Fixes

Will be coming up with list of issues encountered and their fixes.