TFT display and aria g25

 

tftariag25
I made a TJCTM24024 LCD working on aria g25
http://www.elecfreaks.com/store/24-tft-lcd-tft0124sp-p-785.html

The connections are below :
LCD  ARIA

Vin   5V
GND   GND
LED  3.3V
CS   PA14
RESET PA22
DC    PA23
MOSI  PA12
MISO  PA11
CLK   PA13

Most instructions come from http://www.acmesystems.it/arietta_adafruit_lcd28

The  acme-aria.dts concerning the TFT display is

spi0: spi@f0000000 {
status = "okay";
cs-gpios = <&pioA 14 0>;

device@0 {
/* rotate = ;*/

fps = ;
compatible = “fb_ili9341”;
spi-max-frequency = ;
reg = ;
/* regwidth = ;*/
buswidth = ;
verbose = ;
reset-gpios = <&pioA 22 0>; /* PA22 – Karim */
dc-gpios = <&pioA 23 0>; /* PA23 – Karim */

};

};

 

I have added an USB Audio device to add headphones and I have compiled the kernel following http://en.gnublin.org/index.php/Audio

root@acmeboard:~# mplayer -framedrop -ao alsa -cache 8192 -vo fbdev -vfm ffmpeg
-lavdopts lowres=1:fast:skiploopfilter=all perunpugnodidollari.mp4

 

 

GPS + aria G25

GPS module
GPS module

 

20150111_150432

 

20150111_150444

 

Set date :
date -s “11 JAN 2014 13:46:00”
hwclock –systohc

Install CRON : apt-get install cron

root@acmeboard:~# cat check.sh gps.py

#!/bin/sh
SERVICE='gps.py'

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
echo "$SERVICE is not running"
cd /root/
nohup python ./$SERVICE > /dev/null &
fi

[python]
import serial

import logging
import logging.handlers

# set up logging to file – see previous section for more details
logging.basicConfig(level=logging.DEBUG,
format=’%(asctime)s %(name)-12s %(levelname)-8s %(message)s’,
datefmt=’%y-%m-%d %H:%M’,
)

log = logging.getLogger(‘toto’)

formatter = logging.Formatter(‘%(asctime)s %(name)-12s %(levelname)-8s %(message)s’)
handler = logging.handlers.TimedRotatingFileHandler(‘test.log’,’midnight’,1)
handler.setFormatter(formatter)
log.addHandler(handler)

ser = serial.Serial(‘/dev/ttyS4’, 9600, timeout=1)
print("connected to: " + ser.portstr)

while True:

line = ser.readline()
log.debug(str(line.strip()))
[/python]

root@acmeboard:~# crontab -l
*/2 * * * * /root/check.sh >> /root/toto

Convert NMEA lat, lon to decimal lat,lon :

NMEA Decimal
latitude 0302.78469 03 + (02.78469/60) = 3.046412
longitude 10141.82531 101 + 41.82531/60) = 101.6971

Follow the electrical consumption

It is made with ARIA G25 with ethernet and 1 serial port and 1 teleinfo module.

[python]

import serial
import datetime

import json
import urllib2

class SenseDevice:
base_url = ‘http://api.sen.se/events/’
data = []

def __init__(self, api_key):
self.api_key = api_key

def add_value(self, feed_id, value):
self.data.append({
‘feed_id’: feed_id,
‘value’: value
})

def publish(self):
req = urllib2.Request(self.base_url)
req.add_header(‘sense_key’, self.api_key)
req.add_header(‘content-type’, ‘application/json’)

req.add_data(json.dumps(self.data).encode(‘utf-8’))
res = urllib2.urlopen(req)
self.data = []
return res

t0=datetime.datetime.now()

ser = serial.Serial(‘/dev/ttyS4’, 9600, timeout=1)
print("connected to: " + ser.portstr)

a=SenseDevice(‘XXXXXXXXXXXX’)
while True:
# Read a line and convert it from b’xxx\r\n’ to xxx
line = ser.readline()[:-2]
print line
if ‘HCHP’ in line:
val1=line.split()[1]

if ‘HCHC’ in line:
val2=line.split()[1]

t1=datetime.datetime.now()

if (t1-t0).seconds > 60 :
t0=t1
print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),val1,val2
a=SenseDevice(‘XXXXXXXXXXXXXXXXXA’)
a.add_value(49711,float(val1)/1000.0)
a.add_value(54884,float(val2)/1000.0)
res=a.publish()
print res

ser.close()

[/python]

Recompile kernel for Aria G25 to have the DLINK WIFI USB dongle working

Update with kernel 3.16.1

On my laptop :

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria_defconfig

make ARCH=arm menuconfig

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- acme-aria.dtb
make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage
make modules -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
make modules_install INSTALL_MOD_PATH=./modules ARCH=arm

scp arch/arm/boot/dts/acme-aria.dtb root@192.168.1.41:/boot/at91-ariag25.dtb

scp arch/arm/boot/uImage root@192.168.1.41:/boot/image.bin

I had to install rsync on the aria g25 board (apt-get install rsync
rsync -avc modules/lib/ root@192.168.1.41:/lib/

Then reboot the acme card

once rebooted, do

depmod -a

apt-get install firmware-realtek
echo 2001 330d > /sys/bus/usb/drivers/rtl8192cu/new_id

I see with dmesg :

rtl8192cu: Chip version 0x11
rtl8192cu: MAC address: f8:e9:03:d5:03:8a
rtl8192cu: Board Type 0
rtl_usb: rx_max_size 15360, rx_urb_num 8, in_ep 1
rtl8192cu: Loading firmware rtlwifi/rtl8192cufw_TMSC.bin
usb 2-1: Direct firmware load failed with error -2
usb 2-1: Falling back to user helper
rtlwifi: Loading alternative firmware rtlwifi/rtl8192cufw.bin
ieee80211 phy0: Selected rate control algorithm ‘rtl_rc’
rtlwifi: wireless switch is on

root@acmeboard:~# cat /proc/net/wireless
Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
wlan0: 0000 0 0 0 0 0 0 0 0 0

apt-get install wireless-tools

and process as below to set the /etc/network/interfaces

then

/etc/init.d/networking restart

To have this ok at boot, add the 2 lines below in /etc/rc.local

echo 2001 330d > /sys/bus/usb/drivers/rtl8192cu/new_id

/etc/init.d/networking restart

————————————————————–

Following instructions from :

http://www.acmesystems.it/dlink_wifi

Add a USB connector to the board : http://www.acmesystems.it/ariag25_wirings

Recompile the kernel 2.6.39 (http://www.acmesystems.it/ariag25_compile_linux_2_6_39)

In linux-2.6.39/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c, you have to add a line for your dongle :

/****** 8192CU ********/
{RTL_USB_DEVICE(0x0586, 0x341f, rtl92cu_hal_cfg)}, /*Zyxel -Abocom*/
{RTL_USB_DEVICE(0x07aa, 0x0056, rtl92cu_hal_cfg)}, /*ATKK-Gemtek*/
{RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Funai -Abocom*/
{RTL_USB_DEVICE(0x07b8, 0x8178, rtl92cu_hal_cfg)}, /*Abocom -Abocom*/
{RTL_USB_DEVICE(0x2001, 0x3307, rtl92cu_hal_cfg)}, /*D-Link-Cameo*/
{RTL_USB_DEVICE(0x2001, 0x3309, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
{RTL_USB_DEVICE(0x2001, 0x330a, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
{RTL_USB_DEVICE(0x2001, 0x330d, rtl92cu_hal_cfg)}, /*D-Link-Alpha*/
{RTL_USB_DEVICE(0x2019, 0xab2b, rtl92cu_hal_cfg)}, /*Planex -Abocom*/
{RTL_USB_DEVICE(0x7392, 0x7822, rtl92cu_hal_cfg)}, /*Edimax -Edimax*/
{}

You need rtl8192cufw.bin  in  /lib/firmware/rtlwifi/ (it is not installed when you install the package firmware-realtek)

In /etc/network/interfaces (WEP key) :


auto wlan0
iface wlan0 inet dhcp
wireless-essid Freebox-XXXX
wireless-key XXXXXX

The Wifi USB dongle must not be too far from the access point.

You got :

...
sb 2-1: new full speed USB device number 2 using at91_ohci
usb 2-1: not running at top speed; connect to a high speed hub
usb 2-1: New USB device found, idVendor=2001, idProduct=330d
usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-1: Product: 802.11n WLAN Adapter
usb 2-1: Manufacturer: Realtek
usb 2-1: SerialNumber: 00e04c000001
rtl8192cu: MAC address: f8:e9:03:d5:03:8a
rtl8192cu: Board Type 0
rtl8192cu: rx_max_size 15360, rx_urb_num 8, in_ep 1
ieee80211 phy0: Selected rate control algorithm 'rtl_rc'
rtl8192cu 2-1:1.0: wlan0: Features changed: 0x00004800 -> 0x00004000
....
rtl8192cu: MAC auto ON okay!
rtl8192cu: Tx queue select: 0x05
rtl8192cu: Loading firmware file rtlwifi/rtl8192cufw.bin
wlan0: authenticate with f4:ca:e5:ab:22:2c (try 1)
wlan0: authenticated
wlan0: associate with f4:ca:e5:ab:22:2c (try 1)
wlan0: RX AssocResp from f4:ca:e5:ab:22:2c (capab=0x411 status=0 aid=3)
wlan0: associated
...

20141230_004649
Electronic circuit to follow my electrical consumption and publish the results on the net.

ARIA G25 board

The card comes from ACME.

I have wired the following components :

  • ethernet
  • usb port
  • microsd (for the OS Linux)
  • A GPIO output (for the relay)
  • the SPI bus (for the MCP4822)

Use a DAC MCP4822 with the ARIA G25

On the ARIA G25, I use the following C code to control the MCP4822 using the SPI interface :

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

static void pabort(const char *s)
{
perror(s);
abort();
}

static const char *device = “/dev/spidev0.0”;
static uint8_t mode = 3;
static uint8_t bits = 8;
static uint32_t speed = 1000000;
static uint16_t delay;

void affichebin16(unsigned n)
{
unsigned bit = 0 ;
unsigned mask = 1 ;
int i;
for (i = 0 ; i < 16 ; ++i)
{
bit = (n & mask) >> i ;
printf(“%d”, bit) ;
mask <<= 1 ;
}
printf(“\n”);
}

void affichebin8(unsigned n)
{
unsigned bit = 0 ;
unsigned mask = 1 ;
int i;
for (i = 0 ; i < 8 ; ++i)
{
bit = (n & mask) >> i ;
printf(“%d”, bit) ;
mask <<= 1 ;
}
printf(“\n”);
}

static void transfer(int fd, int sortie, int val)
{
int ret;

affichebin16(val);

uint16_t A;
if ( sortie == 1)
A=( val & 0b0000111111111111) | 0b0011000000000000;
else
A=( val & 0b0000111111111111) | 0b1011000000000000;
affichebin16(A);

uint8_t SH = (A & 0xFF00) >> 8; // MSB (bits 9 à 16)
uint8_t SL = A & 0x00FF; // LSB (bits 1 à 8)

printf(“bits 1 à 8 =\n”);
affichebin8(SL);
printf(“bits 9 à 16 =\n”);
affichebin8(SH);

uint8_t tx[] = {
//5V
SH,SL
// 2048 2.5
//0x38,0x00
//0V
//0x30,0x00
};

uint8_t rx[ARRAY_SIZE(tx)] = {0, };

struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,
.rx_buf = (unsigned long)rx,
.len = ARRAY_SIZE(tx),
.delay_usecs = delay,
.speed_hz = 0,
.bits_per_word = 0,
};

ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret == 1)
pabort(“can’t send spi message”);

for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {
if (!(ret % 6))
puts(“”);
printf(“%.2X “, rx[ret]);
}
puts(“”);
}

int main(int argc, char *argv[])
{
int ret = 0;
int fd;

int val=atoi(argv[2]);
int sortie=atoi(argv[1]);

printf(“val=%d\tsortie=%d\n”,val,sortie);

fd = open(device, O_RDWR);
if (fd < 0)
pabort(“can’t open device”);

ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
pabort(“can’t set spi mode”);

ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
pabort(“can’t get spi mode”);

ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
pabort(“can’t set bits per word”);

ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
pabort(“can’t get bits per word”);

ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort(“can’t set max speed hz”);

ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort(“can’t get max speed hz”);

printf(“spi mode: %d\n”, mode);
printf(“bits per word: %d\n”, bits);
printf(“max speed: %d Hz (%d KHz)\n”, speed, speed/1000);

transfer(fd,sortie,val);

close(fd);

return ret;
}

Once compiled the parameters are the output (0 or 1) and the byte to convert.