.
Sunday, February 12, 2012
Farewell Whitney Houston
.
Friday, December 16, 2011
Arduino Lilypad CyberHat
Arduino LilyPad is a special version of Arduino, designed by Leah Buechley at MIT Media Lab. It is specifically designed for integration in clothes and garments. With a special conductive thread, you can sew it on your jacket, and it is easy to program it with the same Arduino IDE we use for the standard Arduino boards.
Check Leah's great LilyPad tutorial which is a great introduction to this wonderful device.
I bought an Arduino LilyPad Simple board kit (LilyPad Beginner's kit), online from british shop SkPang: http://www.skpang.co.uk/catalog/lilypad-beginners-kit-p-967.html I bought again (using paypal account) from this shop and I got good service and fast delivery.
This kit includes a simple version of the Lilypad(*), a lithium LiPO 1 cell 3.7V battery, 5 leds, a multicolored led, a loudspeaker, a vibration button, a light sensor, a temperature sensor, and two spools of conductive thread, along with needles. There is also the small "FTDI basic" board that allows to connect to pc USB via a cable (not included): I use a Nokia DKE-2 phone cable, the same to talk with other arduinos equipped with "USB2Serial light".
(*) This simple Lilypad version differs from the standard one, because has less "petals" (9 available I/Os). But it has a plug for the included 1 cell 3.7V LiPO battery, and the recharging circuit to recharge it from the USB connector. I think these features are not available in the standard LilyPad, which requires an external power supply and is powered via conductive threads.
Arduino LilyPad should not be powered with more than 5Vdc.
-
In the winter, I am using a cap that I bought in Riga, Latvia. It is made of wool felt. It is a perfect fit for a first project for electronic integration with cloth.
Here are some pictures of the hat:
And this is a particular image of a led. It is quite small. Connecting threads are invisible from the outside.
And here is a detail view of the inside. I had to use some thermal glue to have the components stick well on the cloth material. The small circle on top is the speaker, while the one on the bottom right is the multicolored led.
The board, being inside just sits on top of my head when I am wearing the cap. It is completely invisible from the outside, and also the leds are very small and fit nicely in the felt. You would not say this hat has anything unusual until I turn it on. :-)
Code is very simple. I just prepared a set of routines for some light effects on the 5 blue leds, a small tune (shamelessly copied from arduino sample code library), and some random flickering of the multicolored led.
Enjoy!!!!!
------------
/* ledcap lilypad Marco Guardigli I dressed a winter cap with an arduino lilipad mgua@tomware.it this code is GPL. see www.gnu.org */ #include---------------#define LEDFC 10 // front center #define LEDFR 11 // front right #define LEDFL 9 // front left #define LEDBR 19 // back right #define LEDBL 6 // back left #define MCLR 16 // multicolor led: Blue (when low) #define MCLB 17 // multicolor led: red (when low) #define MCLG 18 // multicolor led: green (when low) #define SPK 5 // speaker int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; int noteDurations[] = { 4,8,8,4,4,4,4,4 }; // note durations: 4 = quarter note, 8 = eighth note, etc.: void sing() { Serial.println("sing"); for (int thisNote = 0; thisNote < 8; thisNote++) { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[thisNote]; tone(SPK, melody[thisNote],noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(SPK); } } void setup() { Serial.begin(9600); Serial.println("Init"); pinMode(LEDFC, OUTPUT); pinMode(LEDFR, OUTPUT); pinMode(LEDFL, OUTPUT); pinMode(LEDBR, OUTPUT); pinMode(LEDBL, OUTPUT); pinMode(MCLR, OUTPUT); pinMode(MCLG, OUTPUT); pinMode(MCLB, OUTPUT); pinMode(SPK, OUTPUT); digitalWrite(LEDFC,LOW); digitalWrite(LEDFR,LOW); digitalWrite(LEDFL,LOW); digitalWrite(LEDBR,LOW); digitalWrite(LEDBL,LOW); digitalWrite(MCLR,HIGH); // multicolor led is off when the inputs are all high digitalWrite(MCLG,HIGH); digitalWrite(MCLB,HIGH); digitalWrite(SPK,LOW); delay(1000); sing(); } // RGB // LLL purple // HLL orange // LHL deeppurple // LLH light blue // LHH blue // HHL red // HLH green // HHH off void rainbow() { Serial.println("rainbow"); for (int i=1; i < random(100); i++) { if (random(100)>50) { digitalWrite(MCLR,LOW); } else { digitalWrite(MCLR,HIGH); } if (random(100)>50) { digitalWrite(MCLG,LOW); } else { digitalWrite(MCLG,HIGH); } if (random(100)>50) { digitalWrite(MCLB,LOW); } else { digitalWrite(MCLB,HIGH); } delay(50); digitalWrite(MCLR,HIGH); digitalWrite(MCLG,HIGH); digitalWrite(MCLB,HIGH); delay(50); } } void allblink() { Serial.println("allblink"); for (int i=1; i < random(100); i++) { digitalWrite(LEDFC,HIGH); digitalWrite(LEDFR,HIGH); digitalWrite(LEDFL,HIGH); digitalWrite(LEDBR,HIGH); digitalWrite(LEDBL,HIGH); delay(random(100)); digitalWrite(LEDFC,LOW); digitalWrite(LEDFR,LOW); digitalWrite(LEDFL,LOW); digitalWrite(LEDBR,LOW); digitalWrite(LEDBL,LOW); delay(random(100)); } } void randomblink() { Serial.println("randomblink"); int lev = random(100); for (int i=1; i < random(100); i++) { if (random(100) > lev) { digitalWrite(LEDFC,HIGH); } if (random(100) > lev) { digitalWrite(LEDFR,HIGH); } if (random(100) > lev) { digitalWrite(LEDFL,HIGH); } if (random(100) > lev) { digitalWrite(LEDBR,HIGH); } if (random(100) > lev) { digitalWrite(LEDBL,HIGH); } delay(random(100)); digitalWrite(LEDFC,LOW); digitalWrite(LEDFR,LOW); digitalWrite(LEDFL,LOW); digitalWrite(LEDBR,LOW); digitalWrite(LEDBL,LOW); } } void spinleft() { Serial.println("spinleft"); int d = random(500); int d1 = random(100); digitalWrite(LEDFC,HIGH); delay(d); digitalWrite(LEDFL,HIGH); delay(d1); digitalWrite(LEDFC,LOW); delay(d); digitalWrite(LEDBL,HIGH); delay(d1); digitalWrite(LEDFL,LOW); delay(d); digitalWrite(LEDBR,HIGH); delay(d1); digitalWrite(LEDBL,LOW); delay(d); digitalWrite(LEDFR,HIGH); delay(d1); digitalWrite(LEDBR,LOW); delay(d); digitalWrite(LEDFC,HIGH); delay(d1); digitalWrite(LEDFR,LOW); delay(d); digitalWrite(LEDFC,LOW); } void spinright() { Serial.println("spinright"); int d = random(100); int d1 = random(50); digitalWrite(LEDFC,HIGH); delay(d); digitalWrite(LEDFR,HIGH); delay(d1); digitalWrite(LEDFC,LOW); delay(d); digitalWrite(LEDBR,HIGH); delay(d1); digitalWrite(LEDFR,LOW); delay(d); digitalWrite(LEDBL,HIGH); delay(d1); digitalWrite(LEDBR,LOW); delay(d); digitalWrite(LEDFL,HIGH); delay(d1); digitalWrite(LEDBL,LOW); delay(d); digitalWrite(LEDFC,HIGH); delay(d1); digitalWrite(LEDFL,LOW); delay(d); digitalWrite(LEDFC,LOW); } void front3() { Serial.println("front3"); int ton=random(50); int toff=random(500); for (int i = 1; i < 10; i++) { digitalWrite(LEDFC,HIGH); digitalWrite(LEDFR,HIGH); digitalWrite(LEDFL,HIGH); delay(ton); digitalWrite(LEDFC,LOW); digitalWrite(LEDFR,LOW); digitalWrite(LEDFL,LOW); delay(toff); } } void loop() { // cycles random effects switch (random(10)) { case 0: rainbow(); break; case 1: if (random(100) > 90) { sing(); } break; case 2: allblink(); break; case 3: spinleft(); break; case 4: spinright(); break; case 5: front3(); break; case 6: randomblink(); break; default: delay(1000); } delay(1000); }
Friday, November 18, 2011
TomWare Arduino-Ethernet Datalogger
last updated on nov 18 2011
For a customer project I needed to build a datalogger that had to be periodically and asynchronously polled via ethernet. Main task of the datalogger was counting raising pulses from an external sensor outputting a TTL 0-5v signal.
Customer requirements were to have it simple, reliable, and tolerant of possible ethernet network disconnections.
I decided to work using the new Arduino Ethernet, which integrates the wiznet ethernet shield, and also has the sdcard slot.
I made this with Arduino022 software version.
I needed to perform accurate timestamping in the logs, so I decided to use NTP protocol to periodically sync a local clock built via the DS1307RTC time library.
Given the nature of the pulses I had to count, I decided to simply connect the counter line using the interrupt feature, and so decoupling the pulse detection from all the other code.
After initializing network, sdcard, synchronizing time with NTP server, and setting up the interrupt pulsereading line, the main loop just cycles waiting for browser to connect, then checking if it is time to log on the sdcard, and checking if it is time to resync clock with NTP to avoid excessive drift.
To test it, I built a simple random pulse generator and run it on another arduino 2009, feeding its digital output to the Arduino ethernet pulsecounter in.
I used just the external timekeeping library
http://www.arduino.cc/playground/uploads/Code/Time.zip
Here is the code. Some portions are freely taken from arduino libraries samples. Also I got some inspiration from this page by Ms. Limor Fried (aka LadyAda) describing her SDcard Datalogger and Ethernet server. My SD code is different (and a bit simpler) because I use the standard SD card library.
/*
Web Server, Pulse Logger, NTP time client, for Carcano spa
31.10.2011
This code is GPL. see www.gnu.org for details
be careful in increasing string space. this software uses almost all the arduino ATMEGA328 memory (2Kb)
SDcard Datalogger v0.8
mgua@tomware.it
fgentili@tomware.it
Arduino-Ethernet:
TCPIP Webserver with
NTP client
Asynchronous Interrupt (IRQ0) pulse counter on Digital pin2
DataLogger on Micro SDcard file
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
* Digital input with raising front pulse counter on digital PIN2
NTP protocol is used to sync from a time server
in arduino 022 download time.zip
http://www.arduino.cc/playground/Code/Time
http://www.arduino.cc/playground/uploads/Code/Time.zip
and put its contents in
libraries/DS1307RTC
libraries/Time
libraries/TimeAlarms
SDcard is accessed via SPI protocol standard, which is also used to program ethernet Wiznet controller.
In order to interact with SD, we need to set pin10 as output otherwise SD library will not work
*/
#include
#include
#include
#include
#include
byte mac[] = { 0xDA, 0xAD, 0xBE, 0xEE, 0xFE, 0xED };
byte ip[] = { 10, 2, 3, 51 };
byte mask[] = { 255, 255, 0, 0 };
byte gateway[] = { 10, 2, 0, 1 };
byte timeServer[] = { 10, 2, 3, 60 };
// seconds to add to UTCtime to consider correct timezone
// const unsigned long UTCcorrection = 7200; // CET = UTC + 1 (+2 in summer): (HOW to properly calculate DST?)
const unsigned long UTCcorrection = 0; // keep UTC
const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets
unsigned int localPort = 8989; // local port to listen for UDP packets
Server server(80); // local listener port for http services
// variable for pulsecounter, to be altered from inside interrupt routine (requires volatile)
volatile unsigned long pulses = 0;
int pulsePin = 2; // use pin2 for async pulse counter IRQ0 is connected to PIN2, (IRQ1 is connected to pin 3)
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = seventyYears;
const int EthChipSelect = 10;
const int SDChipSelect = 4;
time_t logInterval = 10UL; // append to file every loginterval seconds
time_t lastLogTime = 0UL;
time_t syncInterval = 60UL; // ntp sync every syncinterval seconds
time_t lastSyncTime = 0UL;
unsigned long logLinesWritten = 0;
const int maxLogLines = 7;
boolean fileFull = false;
char* logFileName = "log.txt";
unsigned long logFileSize = 0; //logfilesize added from last powerup
unsigned long sendNTPpacket(byte *address) {
memset(packetBuffer, 0, NTP_PACKET_SIZE); // set all bytes in the buffer to 0
// Initialize values needed to form NTP request
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// Now send packet requesting a timestamp to server udp port NTP 123
Udp.sendPacket( packetBuffer,NTP_PACKET_SIZE, address, 123);
}
void ntpTimeSync() {
sendNTPpacket(timeServer); // send an NTP packet to a time server & wait if a reply is available
delay(1000);
if ( Udp.available() ) {
Udp.readPacket(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, esxtract the two words:
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a longint: NTP time (seconds since Jan 1 1900)
unsigned long secsSince1900 = highWord << 16 | lowWord;
// NTP gives secs from 1 1 1900. Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
// subtract seventy years:
epoch = secsSince1900 - seventyYears;
Serial.print("T=");
} else {
Serial.print("Te!");
}
Serial.println(epoch);
time_t t = epoch + UTCcorrection;
setTime(t); // sets arduino internal clock
}
String getTimeString() {
// gives back hh:mm:ss
time_t t = now();
String s = "";
if (hour(t) <10) s = s + "0";
s = s + hour(t) + ":";
if (minute(t) <10) s = s + "0";
s = s + minute(t) + ":";
if (second(t) <10) s = s + "0";
s = s + second(t);
return(s);
}
String getDateString() {
// gives back dd/mm/yyyy
time_t t = now();
String s = "";
if (day(t) <10) s = s + "0";
s = s + day(t) + "/";
if (month(t) <10) s = s + "0";
s = s + month(t) + "/";
s = s + year(t);
return(s);
}
void tic() { // IRR Interrupt response routine, bump counter when signal raising front seen
pulses++;
}
void setup()
{
Serial.begin(9600);
Serial.print("R:");
Serial.println(FreeRam());
// setup interrupt logic
pinMode(pulsePin, INPUT); // non strettamente necessaria, in quanto IRQ0 e' sempre agganciata a pin2
attachInterrupt(0, tic, RISING); // LOW-CHANGE-RISING-FALLING tic is the function pointer to the RRI
Serial.println("I");
Ethernet.begin(mac,ip,gateway,mask);
Udp.begin(localPort);
Serial.println("E");
ntpTimeSync();
Serial.print("SD");
pinMode(EthChipSelect, OUTPUT);
if (!SD.begin(SDChipSelect)) {
Serial.println("e!");
while(1); // fatal: wait forever
}
Serial.println();
Serial.println("H");
server.begin();
Serial.println("-");
}
void webServer() {
// sends log content if something is specified
String creq;
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c != '\n' && c != '\r') {
creq += c;
continue;
}
}
Serial.print("[");
Serial.print(creq);
Serial.println("]");
if (creq[5] != 'x' && creq[5] != 'X') { // http://172.30.4.47/x or http://172.30.4.47/X requests log, else std page
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("TomWare PulseLogger 0.8");
client.println("http://ip/X ->log");
client.println("
");
client.print("T:");
client.print(getTimeString());
client.println("");
client.print("D:");
client.print(getDateString());
client.println("
");
client.print("p2 pulses:");
client.print(pulses);
client.print("
");
client.print("log:");
client.print(logFileName);
client.println("
");
client.print("lines:");
client.print(logLinesWritten);
client.println("
");
client.print("logsize:");
client.print(logFileSize);
client.println("
");
client.print("ram:");
client.print(FreeRam());
client.println("
");
} else { // LOG REQUESTED
File dataFile = SD.open(logFileName, FILE_READ);
if (! dataFile) {
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("File Not Found!");
}
Serial.println("W");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/plain");
client.println();
char k;
while ((k = dataFile.read()) > 0) {
client.print((char)k);
}
dataFile.close();
if (fileFull) { // start a new file if file full, deleting contents just sent
Serial.print("D");
SD.remove(logFileName);
Serial.println(".");
fileFull = false;
}
}
delay(1); // give the web browser time to receive the data
client.stop();
}
}
}
void logToFile() {
// always log to logFileName file
File logFile = SD.open(logFileName, FILE_WRITE);
if (logFile) {
String s = "";
time_t t = now();
s = String(t) + "," + String(pulses);
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
s += ",";
s += String(analogRead(analogChannel));
}
logFile.println(s);
logFileSize = logFile.size();
logFile.close();
Serial.println(s);
logLinesWritten++;
} else {
Serial.println("SDe!");
while(1); // fatal: wait forever
}
}
void loop() {
webServer();
time_t t = now();
if ((t - lastLogTime) >= logInterval) {
lastLogTime = t;
Serial.print("F:");
Serial.println(FreeRam());
Serial.print("L:");
Serial.println(logLinesWritten);
logToFile();
if ((logLinesWritten % maxLogLines) == 0) {
Serial.println("FF");
fileFull = true;
}
}
if ((t - lastSyncTime) > syncInterval) {
lastSyncTime = t;
Serial.println("N");
ntpTimeSync();
}
}
@mgua .
Thursday, October 6, 2011
Thank you, Steve Jobs
left
your marks
on this shore
sang
your song
in the wind
dared
to think
different
to do it
always
the harder, better way
striving
always
for excellence
thank you
for the lessons
and the change.
@mgua
Here is a beautiful tribute video I found on Youtube: (added feb 2, 2012)
.
Saturday, October 1, 2011
Arduino Ethernet
Here are some notes about my experience with the new (summer 2011) Arduino-Ethernet.
Arduino Ethernet is a single board which integrates a basic Arduino UNO with Wiznet Ethernet shield.
The board is obviously more integrated, and the components are much smaller.
The board has a MicroSD slot, like the newest Ethernet Shields, but does not have anymore a direct USB interface, like the Arduino Classic boards.
Arduino Ethernet supports a POE addon that allows Power Over Ethernet. I did not buy that too.
To program it, it is needed a small component (also manufactured by the arduino factories, but sold separatedly) called Arduino USB2SERIAL light, that plugs on a 6 pin connector on the board.
This component also can power via USB the whole Arduino. Once programmed, and once ethernet communications are setup, this component is not necessary anymore and can be disconnected, but then Arduino must be powered via the power plug, or via POE.
Here is a picture of the two connected, and with a micro-SD card inside the socket:
You can also program Arduino using a standard serial RS232 interface, connected to GND, RX (digital pin 0), TX (digital pin 1).
Manufacturer
My Arduino Ethernet is manufactured by Smart Projects srl.
I was pleased to find a nice booklet inside the package, with 6 small cool adhesives. Here is the introductory note:
Connection Problems
I was surprised not to be able to connect to my new Arduino thru the standard software already available in my PC (from which I was working on my other Arduino 2009 boards).
The latest (as of oct 1, 2011) distribution package arduino-22 does not support this board, and the USB2SERIAL drivers are simply not there.
My environment is Windows 7 64bit.
After some panic, and after some unuseful trials to download and use FTDI drivers, I found this note: http://scuola.arduino.cc/it/content/getting-started-arduino-ethernet by Federico_Vanzati.
Actually, the correct USB drivers for USB2SERIAL Light can be downloaded from http://arduino.cc/en/Main/USBSerial or http://arduino.cc/en/uploads/Main/Arduino_USBSerial.zip as well as this necessary update of the boards.txt file is needed in arduino-22 distribution so to correctly identify Arduino Ethernet.
With this driver and with the boards.txt update, Arduino Ethernet was correctly identified and i was able to download and run sketches on it.
Available I/O: Caveats
Since Arduino Ethernet is actually and Arduino embedding Wiznet 5100 Shield, some pins are not available, because used by the ethernet interface.
Here is a good description of the Arduino Ethernet architecture, which is based on ATMEL ATMega328.
Digital I/O 10,11,12,13 are not available, since used for ethernet interfacing (exactly like in the Ethernet shield).
Digital I/O 4 is used for interfacing with SDcard.
Digital I/O 0,1 are used for serial interface (native or via USB2SERIAL connector)
So, the available Pins are:
7 Digital I/O: 2,3,5,6,7,8,9
of these, PIN 2,3 can support interrupt triggering, to detect an asynchronous change in a signal, like detecting an edge (see AttachInterrupt()) and for example could be used for pulse counting.
PIN 7 is a normal digital I/O
PINs 3,5,6,9 can support PWM (pulse width modulation, needed for example in servo controlling).
6 Analog I/O 0,1,2,3,4,5 can be used to read/write analog values with 10 bit resolution (4.9mV) in the range 0-5V.
@mgua
.
Sunday, September 11, 2011
How I became an hollywood actor
So strange that almost seems impossible.
But it is true.
Absolutely.
My mom Adriana died on sept 11, 2008.
About two months after her loss, I found a website: http://myparentswereawesome.tumblr.com where many send old pictures of their parents.
I decided to send this picture, where mom holds me, as a very little child. Along with the picture I left my email address.
In april 2010, that picture was published. And I was very happy because I felt that my mom picture was available on the web, and maybe other people could see her. I did non even write she was dead. It was a sort of private joy for me knowing that "our" picture was online.
I did not even tell the story to anyone.
Months later, I received an email from a lawyer, Ashley Kravitz, working for CBS copyright cleaning.
CBS wanted to use my mom picture in a movie!
The movie is an action packed gangster story: Faster, starring Dwayne Johnson and Billy Bob Thornton
And at 53 minute in the movie, there is my mom, and there is me.
So, this is how I became an hollywood actor in an action movie.
Life is wonderful.
@mgua
.
for our moms
for our moms
moms are
made of a matter
that is hard and tender
moms are gifts
from past to future
seeds for your flowers
moms work
plan, dream
for a distant future
and give unselfishly
care and care
with the warmest endless trust
moms do not
need words
for understanding
moms do not ask
do not expect
never leave you alone
their core within
your future
your story
and they give
their greatest gift
when leaving
mgua
-crossposted from
http://www.ebmb.de/http/mbs/board.php?sort=&num=1315776939&thread=1315776939
Monday, August 29, 2011
Be strong. Be alive. Be an example. Be a leader.
Marco ( @mgua )
PS: the Video is not shown in some places. Check this one instead.
http://www.youtube.com/watch?v=wOlTdkYXuzE
.
Thursday, August 25, 2011
Network interface bonding and trunking VLANs with different MTUs on RedHat Linux
(Last updated on aug 30 2011)
Configuration of Red Hat Enterprise Linux Server 6.1 (Hardware: HP DL380G7, 2 CPU Intel core) connected with two 10Gbit/sec ethernet interfaces (HP NC522SFP Dual Port 10GbE Server Adapter Board), with interface bonding, high availability, bandwidth aggregation and multiple VLAN transport.
Two 10Gbit/s physical network interfaces have to be connected to two FEX (Nexus Fabric EXtension "switches") upstreaming to two different Nexus 7000 cores, in a high availability configuration, allowing also to use both links simultaneously, and to transport different VLANs.
The different VLANs have then to be mapped on different linux logical subinterfaces.
The two physical interface are joined to form a bond, called bond0.
A specific channel configuration exists on the cisco nexus switches, so to allow these ports to form a single trunk channel, and to transport on it tagged frames from the selected VLANs, complying to the 802.1q transport.
Here are the settings on the Cisco Nexus Side (only one "side" is shown, the other is symmetric):
Core to FEX2232
interface port-channel131
switchport
switchport mode fex-fabric
fex associate 131
mtu 9216
FEX to server
interface Ethernet131/1/5
description srv
switchport
switchport mode trunk
switchport trunk allowed vlan 10-13
flowcontrol send off
channel-group 88 mode active
no shutdown
On the RedHat linux side, my two physical interfaces are eth0 and eth2. I check with ethtool that on both I can see the link, and that the speed and duplex settings are ok (autonegotiation has been disabled both on the switch side and on the server).
The two physical interfaces are joined in bond0
Here are the configuration files of the physical and logical interfaces, in /etc/sysconfig/network-scripts
bond0.10 and bond0.11 are the two logical interfaces sitting on VLANs 10 and 11
bond0.10 has MTU 1500
bond0.11 has MTU 9000 so to allow more efficient traffic of large blocks of data on the storage VLAN
-------
[root@srv network-scripts]# cat ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
HWADDR=78:e3:b5:f4:e0:50
TYPE=Ethernet
IPV6INIT=no
[root@srv network-scripts]# cat ifcfg-eth2
DEVICE=eth2
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
HWADDR=78:E3:B5:F4:76:E0
TYPE=Ethernet
IPV6INIT=no
[root@srv network-scripts]# cat ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
BONDING_OPTS="mode=4 miimon=100"
IPV6INIT=no
USERCTL=no
MTU=9000
[root@srv network-scripts]# cat ifcfg-bond0.10
IPADDR=192.168.145.248
NETMASK=255.255.254.0
DEVICE=bond0.10
ONBOOT=yes
VLAN=yes
TYPE=Ethernet
HWADDR=78:e3:b5:f4:e0:50
BOOTPROTO=none
GATEWAY=192.168.144.1
IPV6INIT=no
USERCTL=no
MTU=1500
[root@srv network-scripts]# cat ifcfg-bond0.11
IPADDR=192.168.148.85
NETMASK=255.255.255.0
DEVICE=bond0.11
ONBOOT=yes
VLAN=yes
TYPE=Ethernet
BOOTPROTO=none
IPV6INIT=no
USERCTL=no
MTU=9000
[root@srv network-scripts]# ifconfig eth0 && ifconfig eth2 && ifconfig bond0 && ifconfig bond0.10 && ifconfig bond0.11
eth0 Link encap:Ethernet HWaddr 78:E3:B5:F4:E0:50
UP BROADCAST RUNNING SLAVE MULTICAST MTU:9000 Metric:1
RX packets:30750 errors:0 dropped:0 overruns:0 frame:0
TX packets:12992 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3590043 (3.4 MiB) TX bytes:3577302 (3.4 MiB)
Interrupt:53
eth2 Link encap:Ethernet HWaddr 78:E3:B5:F4:E0:50
UP BROADCAST RUNNING SLAVE MULTICAST MTU:9000 Metric:1
RX packets:36472 errors:0 dropped:0 overruns:0 frame:0
TX packets:7248 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:27483898 (26.2 MiB) TX bytes:906669 (885.4 KiB)
Interrupt:61
bond0 Link encap:Ethernet HWaddr 78:E3:B5:F4:E0:50
inet6 addr: fe80::7ae3:b5ff:fef4:e050/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:9000 Metric:1
RX packets:67224 errors:0 dropped:0 overruns:0 frame:0
TX packets:20242 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:31074081 (29.6 MiB) TX bytes:4484967 (4.2 MiB)
bond0.10 Link encap:Ethernet HWaddr 78:E3:B5:F4:E0:50
inet addr:192.168.145.248 Bcast:192.168.145.255 Mask:255.255.254.0
inet6 addr: fe80::7ae3:b5ff:fef4:e050/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:51880 errors:0 dropped:0 overruns:0 frame:0
TX packets:13135 errors:0 dropped:10 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8963296 (8.5 MiB) TX bytes:3972360 (3.7 MiB)
bond0.11 Link encap:Ethernet HWaddr 78:E3:B5:F4:E0:50
inet addr:192.168.148.85 Bcast:192.168.148.255 Mask:255.255.255.0
inet6 addr: fe80::7ae3:b5ff:fef4:e050/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:9000 Metric:1
RX packets:14599 errors:0 dropped:0 overruns:0 frame:0
TX packets:6891 errors:0 dropped:7 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:20770093 (19.8 MiB) TX bytes:486535 (475.1 KiB)
[root@srv network-scripts]# ethtool eth0
Settings for eth0:
Supported ports: [ FIBRE ]
Supported link modes: 10000baseT/Full
Supports auto-negotiation: No
Advertised link modes: 10000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: No
Speed: 10000Mb/s
Duplex: Full
Port: FIBRE
PHYAD: 0
Transceiver: external
Auto-negotiation: off
Supports Wake-on: g
Wake-on: g
Current message level: 0x00000005 (5)
Link detected: yes
[root@srv network-scripts]# ethtool eth2
Settings for eth2:
Supported ports: [ FIBRE ]
Supported link modes: 10000baseT/Full
Supports auto-negotiation: No
Advertised link modes: 10000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: No
Speed: 10000Mb/s
Duplex: Full
Port: FIBRE
PHYAD: 0
Transceiver: external
Auto-negotiation: off
Supports Wake-on: g
Wake-on: g
Current message level: 0x00000005 (5)
Link detected: yes
-------
With this configurations, the server keeps correctly the configuration at reboot, and all the interfaces have the correct MTU sizes.
Performance metering:
With this setup, I was able to squeeze an amazing end-to-end tcp speed of 9.8Gbit/sec
here is the nuttcp test output.
[root@srv network-scripts]# nuttcp -t -v -T 60 192.168.148.85 nuttcp-t: v6.1.2: socket nuttcp-t: buflen=65536, nstream=1, port=5001 tcp -> 192.168.148.85 nuttcp-t: time limit = 60.00 seconds nuttcp-t: connect to 192.168.148.85 with mss=8948, RTT=0.277 ms nuttcp-t: send window size = 28440, receive window size = 87380 nuttcp-t: available send window = 21330, available receive window = 65535 nuttcp-t: 70086.0000 MB in 60.00 real seconds = 1196131.87 KB/sec = 9798.7123 Mbps nuttcp-t: retrans = 0 nuttcp-t: 1121376 I/O calls, msec/call = 0.05, calls/sec = 18689.56 nuttcp-t: 0.2user 29.7sys 1:00real 49% 0i+0d 468maxrss 0+2pf 25844+75csw nuttcp-r: v6.1.2: socket nuttcp-r: buflen=65536, nstream=1, port=5001 tcp nuttcp-r: accept from 192.168.148.86 nuttcp-r: send window size = 28440, receive window size = 87380 nuttcp-r: available send window = 21330, available receive window = 65535 nuttcp-r: 70086.0000 MB in 60.00 real seconds = 1196065.83 KB/sec = 9798.1712 Mbps nuttcp-r: 2319818 I/O calls, msec/call = 0.03, calls/sec = 38661.42 nuttcp-r: 0.4user 33.9sys 1:00real 57% 0i+0d 330maxrss 0+17pf 1103994+76csw [root@srv network-scripts]#
which is a quite good result!
during the nuttcp test, the servers were having about a 50KHz interrupt rate and a very low average load.
here is the vmstat 1 output of the transmitting server during the test:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 15100956 44948 525388 0 0 0 0 280 152 0 0 100 0 0 0 0 0 15100956 44948 525388 0 0 0 0 159 73 0 0 100 0 0 1 0 0 15096676 44948 525388 0 0 0 0 44407 536 0 2 98 0 0 1 0 0 15097296 44956 525384 0 0 0 44 51087 455 0 6 94 0 0 1 0 0 15097792 44956 525388 0 0 0 0 51025 556 0 2 98 0 0 1 0 0 15098056 44956 525388 0 0 0 0 50067 656 0 7 93 0 0 1 0 0 15098304 44956 525388 0 0 0 0 49978 774 0 2 98 0 0 1 0 0 15098676 44956 525388 0 0 0 0 50264 769 0 6 94 0 0 1 0 0 15098676 44956 525388 0 0 0 1076 50428 843 0 2 98 0 0 1 0 0 15098676 44956 525388 0 0 0 0 50832 1202 0 5 95 0 0 0 0 0 15099296 44956 525388 0 0 0 0 51193 1350 0 2 98 0 0 1 0 0 15099544 44956 525388 0 0 0 0 51228 1198 0 7 93 0 0 0 0 0 15102948 44956 525388 0 0 0 0 6756 681 0 0 100 0 0 0 0 0 15103072 44964 525380 0 0 0 360 684 462 0 0 100 0 0 0 0 0 15103400 44964 525388 0 0 0 0 234 147 0 0 100 0 0
Friday, August 19, 2011
Youth
Youth, by Samuel Ullman (1840-1924)
Youth is not a time of life; it is a state of mind; it is not a matter of rosy cheeks, red lips and supple knees; it is a matter of the will, a quality of the imagination, a vigor of the emotions; it is the freshness of the deep springs of life.
Youth means a temperamental predominance of courage over timidity of the appetite, for adventure over the love of ease. This often exists in a man of sixty more than a body of twenty. Nobody grows old merely by a number of years. We grow old by deserting our ideals.
Years may wrinkle the skin, but to give up enthusiasm wrinkles the soul. Worry, fear, self-distrust bows the heart and turns the spirit back to dust.
Whether sixty or sixteen, there is in every human being's heart the lure of wonder, the unfailing child-like appetite of what's next, and the joy of the game of living. In the center of your heart and my heart there is a wireless station; so long as it receives messages of beauty, hope, cheer, courage and power from men and from the Infinite, so long are you young.
When the aerials are down, and your spirit is covered with snows of cynicism and the ice of pessimism, then you are grown old, even at twenty, but as long as your aerials are up, to catch the waves of optimism, there is hope you may die young at eighty.
.
Sunday, May 22, 2011
Apple ipad lost notes
It seems quite a common situation that Apple devices notes are being lost.
The loss of information is always a very frustrating experience, and it is even more frustrating to know that a backup of the lost information is present, but is apparently unaccessible.
The following article is related to my experience on my Ipad, but it is probably applying also to iphone and ipod.
The problem:
Notes on the device appear completely empty.
Possible causes:
1. The user was changing the email account synchronization settings on the device. Maybe an account was removed, or its settings were changed.
2. An itunes sync operation was interrupted abruptly, disconnecting the cable
3. Your ipad was hit by a spell of disgrace (:-).
Possible solutions (basic):
1. If you had Gmail synchronization in place, open your gmail account from your PC, and look for a "Notes" label among your email labels. It can be that your notes are there. If so, save them, and thank big G. Then go back to your ipad and reactivate gmail notes synchronization tapping Settings/Mail,Contacts,Calendar/your Gmail account/">"
2. If you had a non-gmail notes synchronization with your email system, check the settings. Some email systems allow notes synchronization, other do not (as an example, IBM Lotus Traveler do not sync notes).
Possible solution (advanced):
Do not sync your device, and prepare for opening the guts of your iTunes. The reason for not syncing is that apparently iTunes sync operation keeps only a single copy of the last state of the device. It can be you have another backup system that backs up the iTunes folders, so maybe you also have hopes if you already performed an iTunes sync.
The following instructions require some not so common skills, so if you are not confident, please ask for professional help. It can be you will need to enable access and proper visibility to files in these folder, as well as detailed view mode.
The following instructions are based on my iTunes installation on a Windows 7 64 bit english edition. Paths could be different under other operating systems.
On my pc, the iTunes backup folder is this:
in this folder, there are maybe some other folders with ugly names like:
aa076cff33fddfd88fc380964bbcf3792343ff30
Each of which contains the backup data of each apple devices that ever synced with your iTunes setup.
Inside these data folder there are a bunch of files with similarly ugly names and no extensions. There are no subfolders.
In my installation I have 2108 backup data files. File dates and size are very different. Dates and times reflect the moments in which iTunes synchronization updated the file.
Now sort the folder content by last modification date (clicking on the top of column date modified, in view-details mode) and look for the file named info.plist
You have to check this file contents (IMPORTANT: open it without saving any changes) to be sure you are checking the right directory (you could have more than one apple device and you can identify which backup directory you are in by checking the contents of this file).
In order to open this file, you will need a text editor which is somewhat smarter than Microsoft notepad. A good choice could be notepad++ (see http://notepad-plus-plus.org/ ).
Here is an excerpt of my info.plist contents (some data has been edited and replaced with [omissis] placeholder)
The backup data files contain your data. The problem is that the majority of those files are not text files and are not easily readable, and specific tools are needed.
A simple quite unspecific tool is grep, but unfortunately it is not available in basic windows installations. A very good implementation of grep for windows is included in cygwin set of tools, but this requires a big and complex installation.
Windows comes with a simpler tool, called find, that can be useful in our situation.
First we need to open a command box, and go in the aforementioned folder that contains our backup. We use the command "cd" to go to the specific folder (the path was copied and pasted from the explorer window).
We need also an unusual word that was included in one of our lost notes. A surname or any unusual and uncommon word would be great. This will be our bait. We will use the bait to go fishing for our lost notes contents.
In my case I used the word "prodexpo" that was in one of my lost notes, and found it inside a specific file, with the following command line command:
Then I opened (with notepad++) the now identified file and was able to read the contents of one of my lost notes and recover manually the important data (names, emails and phone numbers). (be careful not to save!!).
Further analysis and reverse engineering can be performed using sql-lite tools from cygwin, but this is definitely out of scope here.
---
As a reference, there is a tool named decode_iphone_backup available at the following url which decodes the itunes backup directory in a more suitable filesystem format.
After the decoding, sql-lite tools can be used to access the semi-relational data structures.
The tool is intended to be run on a mac computer, but it is written in pyton, so it is easily understandable.
The tool requires another program called plutil (property list tool) which is part of Apple Mac OSX operating system.
Windows/Linux ports of plutil are probably available here (Erica Sedun great site) here and here, but I dont know if they are current:
The author of the iphone-backup-decoder tool is named Pádraig. The original tool available is dated 2007.
An extended version with a GUI interface appears to be available on the site
which apparently is Pádraig website.
I did not test any of the these tools at the time.
I learned of the existance of Pádraig's tool from a blog post by Sharninder:
Marco ( @mgua )
.
Tuesday, February 22, 2011
Drowning in data
Drowning in Data
We are drowning in data,
But good poetry is still short.
Luckily.
If there were no clouds
boring would be always blue skies.
And sparkling jewels are there
in a whole life,
a few carefully chosen moments
to be framed
without polaroid,
Even to be lost
and yes, wasted
tears in the rain.
Smile.
The shorter the story
the deeper the meaning.
Marco
Image by Dopludo Collective, St. Petersburg.
(text crossposted from ebmb)
Monday, January 10, 2011
Books are dying
I have been an avid reader: for many years.
Actually I grew up with books: reading, and dreaming.
![]() |
| Carl Spitzweg, the bookworm, 1850 |
Books were my friends: loyal, discrete, sincere, silent. They were with me on the train, at school, during many long summer afternoons, and in the deep night. (I remember reading frightening ghost stories while my parents were asleep).
Dear old books are gradually disappearing and passing by. They are shifted away by other forms of entertainment, gradually put aside by screens, and much more quickly consumed.
Books lives are now much shorter than in the past. Far too many books are available, and the content quality of the average book is quickly declining. Many people write books, but the same amount of worth books are written. Signal to noise ratio is going down.
Shop life of a book is now measured in weeks.
Inevitably, cheaper electrons will gradually substitute books.
Books will become a form of classic knowledge, with their inefficient cross-referencing, inability for full text searching, and their unacceptable lack of multimedia content.
Books will get old and dusty. They will be preserving their words for centuries, buried in libraries shelves.
Their pages will become yellow.
Their smell will change.
Some lucky old books will be scanned, and in some way shared to a broader potential amount of readers. Their paper will be digested into magnetic hard disk oxide, in huge datacenters under some mountain.
Books will evaporate, their bits dispersed in computing clouds.
Immaterial, electronic, aseptic, up-to-date, searchable, multimedia ebooks are growing.
Internet connected readers are reding internet connected books.
Book pages will share the screen with email, blogs, social networks, videogames.
E-tears will fall.
Books are dying, yes.
And old Readers are dying too.
| The London Holland-House library after blitz german bombings. Picture taken on oct 1, 1940. |
(My friend Fravia told me about this devastated library picture. Check this page of him about quality books, as described in a great lesson by prof. Fritjhof Sielaff)
Marco
.
Sunday, December 19, 2010
A more conscious resource usage
To improve the world we need to change our habits,
reducing pollution and becoming more responsible.
We need to understand.
We need to be more critic, and think more about our environment.
The story of stuff:
a video from Tides Foundation helping us to understand the production cycle of the goods we consume
We want a better future
We want a better world.
Watch.
Think.
Talk.
And start doing.
Right time is NOW!
Marco
Monday, November 22, 2010
Arduino Wiznet ethernet shield proper reset
Problem: Arduino 2009 with wiznet w5100 ethernet shield does not start network operations after power-up.
It works well if the reset button is pressed.
Solution: I implemented davekw7x's suggestions (THANK YOU!), as cited in this arduino forum page (ref. reply #11)
this solution requires a 10kOhm resistor, and a 10nf capacitor.
Here are the detailed steps and some pictures:
1. bend outwards the ethernet shield reset pin "leg", so that it will not go in the arduino reset socket.
2. solder the 10kOhm resistor between reset pin and the nearby 3.3 Vcc
3. solder the 10nf capacitor between reset pin and ground
Here is a picture of one of my ethernet shields, with the reset "leg" bent outwards.
And this is the details of how I soldered the components on the back of the circuit.
In this position the components are nicely arranged on the back of the board.
With this mod, my arduino + ethernet shield is starting up correctly after powering up, and immediately works with no need of reset button push.
Marco ( @mgua )
.
Rigol DS1052E Oscilloscope
The order from DealExtreme is including shipping.
Unfortunately, a substantial delay (totally unrelated with DealExtreme) was caused by the customs import procedures. Italian posts are terrible.
Overall, it took almost two months to receive the device.
But finally I got it, and in one piece. Package was in good state, and the box was well sealed.
Here is a picture of the product along with box contents, from www.goodluckbuy.com
I have to say that the product quality is very good, and that usability is good too. (apart from the initial shock of having the default menus in chinese, quickly fixed).
The scope is well built, with good quality sturdy plastic chassis, a good color lcd monitor, and good quality knobs.
Furthermore there is a publicly available hack (check here and to actually double the scope frequency bandwidth to 100MHz, actually turning the Rigol DS1052E into the Rigol DS1102E, which has just a difference in firmware.
Here is the spec comparison of the two models, from the instructables.com site page describing the hack.
Also this Dave Jones videoblog entry on youtube describes the hack, as well as some tricks in updating the most recent firmwares so to avoid problems.
I did not apply the hack to my scope yet, because I have currently no need of a higher speed. I will do it as soon as I will have the need.
Here are some manuals and documents of this product, taken from Rigol Website:
User guide
Programming Guide
Specifications
Datasheet
Marco (@mgua)
.
Saturday, October 16, 2010
Farewell mr. Fractal
He was 85.
He poured colour
On otherwise pale equations
He traced the path
Analyzing the bizarre ways
In which numbers play
Between zero and infinity
He was walking to measure
Britain's coast
At various distances
Fractals call him dad
Now he walks
On the white chalky paths
In the Great Attractor's garden.
Farewell.
marco
Friday, October 15, 2010
Gandalf's grey hat
Gandalf's grey hat
Where did Gandalf put his grey robes,
and his grey hat, after his fight with the Balrog?
Absolutes are easier to deal with than tradeoffs
But real beauty lies in between
In the nuances, in fractal dances
In chaotic indecisions, bouncing on spectre's ends
In misteriously misty shades of grey
In mutations, diversity, evolution
Be alive
Cast Doubt
Ready for change
Marco
(crossposted from ebmb)
.
Monday, October 4, 2010
Hacking Your Car
Last edited on jun 27, 2012
CAVEATS: I found that the generally available informations about this subject on the internet is quite poor and not very clear. While I am trying to do my best in verifying, errors and mistakes could be present.
Please feel free to add your critics and comments.
This is going to be a long term project, so this page will be improved over time.
Cars are complex
Cars are getting complex. Car electronics is really sophisticated, and current cars have dozens of control units for managing devices, sensors, and actions.
ECUs: Elecronic Control Units
The Control Units talk on local vehicle networks, which are similar to a common computer LAN, but based on different protocols.
ECUs, Engine Control Units, were the first to be connected to vehicles network, soon followed by others ECUs (generic Electronic Control Units).
To reduce the amount of signal wires among the many electric components of a modern car, digital communication protocols were introduced, and digital electronic interfaces between every electric device and the communication infrastructure.
The most important ECU is the Engine Control Unit.
Here is a non-exaustive list of Engine Control Unit manufacturers for cars: BOSCH (example: EDC16), MAGNETI MARELLI (example: 95160), SAGEM (example: 95080), SIEMENS (example: TMS374).
Here is a PDF file from the chinese company UIF Technology (a supplier of car electronics and diagnostic devices) with pictures of many Engine Control Units.
STANDARDS: a terrible headache
There are many standards defining protocols, signals, diagnostics.
Here is a probably incomplete and maybe wrong list
SAE and ISO are the most common standard and documents frameworks, but there are many others
SAE is the Society of Automotive Engineers.
SAE defines Communications Standard utilized in On-and Off-Road Land-Based Vehicles. In this schema 3 classes of communicating devices are explained:
CLASS A: up to 10Kbit/sec, multipurpose, asynchronous, used for non-realtime, smart sensors, wire reduction.
CLASS B: in the range 10Kbit/sec up to 125Kbit/sec, used for intermodule data transfer and non-realtime control. SAE J1850 is a CLASS B protocol, currently used for low-cost connectivity between nodes like instrumentation and diagnostic devices.
CLASS C: critical, high speed, realtime communications between device. For these needs, hi-speed CAN is currently used (up to 1Mbit/sec), but there are also faster alternatives, like Flexray (up to 10Mbit/sec, firstly implemented in BMW
SAE J1850 describes two different protocols: a low speed single wire VPW (Variable Pulse Width) protocol running at 10.4Kbit/sec and a faster two wire differential PWM (Pulse Width Modulation) protocol running at 41.6Kbit/sec. This is NOT CAN nor is it compatible with CAN.
VPW is classically used by GM (General Motors) vehicles.
PWM is classically used by Ford vehicles.
ISO_9141-2 is not a signaling protocol, but a diagnostic interface to check vehicle component functionality. It is a serial interface that runs at 9.6Kbit/sec. It is often available in OBD-2 connector.
ISO_11992 is a CAN bus used in trucks for communications between the tractor and the trailers.
SAE_J1939 is a set of specification based on an underlying CAN infrastructure, working with 29bit identifiers and usually with a bit rate of 250kbit/sec. This is normally used in trucks and industrial vehicles. It is a prerequisite for the FMS (see forward) system to work. An introduction to SAE_J1939 by Marcus Junger can be found on Vector site here. Other J1939 infos are on can-cia.org,. See also here, and here.
According to wikipedia, SAE_J1939 supersedes SAE_J1708 and SAE_J1587.
Here is a list of Automotive data buses, by Leroy Davis.
Vehicle Networks
Actually there are many vehicle networks, eventually based on different standards, different criticality, different protocols, and different communication speeds. Currently these networks are converging to the CAN standard, but there are many others. Since CAN is now the de-facto standard for vehicle networking, sometimes it is also identified as VDB (Vehicle Data Bus).
Despite its popularity, CAN bus is not the only network inside any modern vehicle, and in a single vehicle there are usually different networks (multiple CAN networks and NON-CAN networks).
CAN
CAN stands for Controller Area Network. It was originally developed by Bosch, starting in 1983. CAN is used in many automation environments and not only in automotive industry.
In a CAN bus all the communicating devices are connected to the same two wires, labeled CAN-High and CAN-Low. All the devices must use the bus at the same speed. At each end, the two wires are connected with a 120 ohm termination resistor. It is not required to have a common ground signal among the communicating devices. Bus maximum length is dependent from the operational speed, and at 1Mbit/sec is about 40m. Vehicle network bus speeds are usually below 500Kbit/sec. High speed bus vehicle implementation often adopt twisted pair wires.
In a normal situation, the two wires carry a two-level signal, perfectly specular, and whenever one is high the other is low. Here are two nice pictures (source: picoauto.com ) representing oscilloscope reading of the two wires of a CAN bus. The second image allow a clear understanding of the specular nature of the signals.
From these pictures, the different logical values of the signals can be read, and here each signal has a span of about 1V. In the upper picture, a full CAN packet transfer is visible. The overall packet transfer time is about 200ms (320-120).
Actual CAN bus voltages are not usually this neat.
Here is an actual example (this too from picoauto) (Voltage references seem nonsensical in this picture).
The CAN Protocol
Currently there are two main version of the CAN protocol
Standard CAN: 2.0A with 11bits identifiers
Extended CAN: 2.0B with 29bits identifiers
CAN is defined in ISO_11519 and ISO_11898.
ISO 11898-2 defines the high speed CAN, up to 1Mbit/sec
ISO 11898-2 high speed
ISO 11898-2 is the most used physical layer standard for CAN networks. It describes the bus access unit (implemented as CAN high-speed transceiver) functions as well as some medium-dependent interface features.ISO 11898-3 (aka ISO 11519-2) defines the fault tolerant (and lower speed) CAN, up to 125Kbit/sec
In this standard the data rate is defined up to 1 Mbit/s with a theoretically possible bus length of 40 m at 1 Mbit/s. The high-speed standard specifies a two-wire differential bus whereby the number of nodes is limited by the electrical busload. The characteristic line impedance is 120 Ohm, the common mode voltage ranges from -2 V on CAN_L to +7 V on CAN_H. The nominal specific propagation delay of the two-wire bus line is specified at 5 ns/m. All these figures are valid only for a 1 Mbit/s transfer rate and a maximum network length of 40 m.
In order to achieve physical compatibility all nodes in the network must use the same or a similar bit-timing. For automotive applications the SAE published the SAE J2284 specification. For industrial and other non-automotive applications the system designer may use the CiA 102 recommendation. This specification defines the bit-timing for rates of 10 kbit/s to 1 Mbit/s. It also provides recommendations for bus lines and for connectors and pin assignment.
ISO 11898-3 fault-tolerant
An alternative form of bus interfacing and arrangement of bus lines is specified in ISO 11898-3 (fault-tolerant CAN). This standard is mainly used for body electronics in the automotive industry. Since for this specification a short network was assumed, the problem of signal reflection is not as important as for long bus lines. This makes the use of an open bus line possible.
This means low bus drivers can be used for networks with very low power consumption and the bus topology is no longer limited to a linear structure. It is possible to transmit data asymmetrically over just one bus line in case of an electrical failure of one of the bus lines.
ISO 11898-3 defines data rates up to 125 kbit/s with the maximum bus length depending on the data rate used and the busload. Up to 32 nodes per network are specified. The common mode voltage ranges between -2 V and +7 V. The power supply is defined at 5 V.
Transceiver chips, which support this standard, are available from several companies. The fault-tolerant transceivers support the complete error management including the detection of bus errors and automatic switching to asymmetrical signal transmission.
The preceding two quotes of text about CAN physical layer specifications are taken from here (fetched on dec 4 2010): http://www.can-cia.org/index.php?id=517
Also there are other physical layer standards.
The following section is shamelessly copied from Staffan Nilsson web page
(with some corrections)
-----------------------
ISO 11898-2 voltage levels (CAN High Speed)
| Signal | recessive state | dominant state | unit | ||||
| min | nominal | max | min | nominal | max | ||
| CAN-High | 2.0 | 2.5 | 3.0 | 2.75 | 3.5 | 4.5 | Volt |
| CAN-Low | 2.0 | 2.5 | 3.0 | 0.5 | 1.5 | 2.25 | Volt |
Note that for the recessive state, nominal voltage for the two wires is the same. This decreases the power drawn from the nodes through the termination resistors. These resistors are 120ohm and are located on each end of the wires. Some people have played with using central termination resistors (that is, putting them in one place on the bus). This is not recommended, since that configuration will not prevent reflection problems.
ISO 11519 voltage levels (CAN Low Speed)
| Signal | recessive state | dominant state | unit | ||||
| min | nominal | max | min | nominal | max | ||
| CAN-High | 1.6 | 1.75 | 1.9 | 3.85 | 4.0 | 5.0 | Volt |
| CAN-Low | 3.1 | 3.25 | 3.4 | 0 | 1.0 | 1.15 | Volt |
ISO 11519 does not require termination resistors. They are not necessary because the limited bit rates (maximum 125 kB/s) makes the bus insensitive to reflections. The voltage level on the CAN bus is recessive when the bus is idle.
Bus lengths
The maximum bus length for a CAN network depends on the bit rate used. It is required that the wave front of the bit signal has time to travel to the most remote node and back again before the bit is sampled. This means that if the bus length is near the maximum for the bit rate used, one should
choose the sampling point with utmost care - one the other hand, one should always do that!
Below is a table of different bus lengths and the corresponding maximum bit rates.
| Bus length (metres) | Maximum bit rate (bit/s) |
| 40 | 1 Mbit/s |
| 100 | 500 kbit/s |
| 200 | 250 kpit/s |
| 500 | 125 kbit/s |
| 6 km | 10 kbit/s |
Cables
According to the ISO 11898 standard, the impedance of the cable shall be 120 +- 12 ohms. It should be twisted pair, shielded or unshielded. Work is in progress on the single-wire standard SAE J2411.
-----------------------
CAN frames
Here are some informations about CAN data frames
the following picture is from http://www.jcelectronica.com/articles/CAN%20bus%20tutorial_2.htm
The Standard and Extended frames are shown, and the different address field length can be seen.
CAN reliability
CAN bus communications are usually very reliable, quite insensitive to external interferences (since external interferences affect similarly both wires, the difference between the voltages remains unchanged), and to single control unit fault. The devices can often work even in case of bus being severely miswired (one cable shorted to ground or to vcc). No need of a common ground also increases robustness. This reliability is among the properties that made it the current standard in difficult environments, with wide temperature ranges, and very varying environmental situations.
Detecting CAN
Since there are many wires, it is not easy to identify the proper ones.
0.CAN signals are usually not present if the key is not turned to power the dashboard. (It is normally not needed that the engine is powered).
1.CAN wires are usually twisted.
2.Checking CAN signal presence without the use of an oscilloscope: A simple test to see if the bus is operating correctly is to use a multimeter and measure the voltage between the two wires. In "perfect" situations, if the bus is active and working it will show a steady 2.5V or 0,5V (in absence of signal changes), or a quick alternance between 0,5 and 2,5V. If not working it will be 0V as one of the CAN controllers on the network is pulling the bus low (known as Bus Off).
3. Operating with a two channels oscilloscope, and using the subtract function between the two signals CAN-H and CAN-L, you should get a constant (because the two signals have opposite phases). Oscilloscope can also help in detecting the speed of the CAN bus signals. (will add details here).
4. An indirect CAN presence indicator could be testing for proper termination. Proper termination of a CAN bus can be easily tested with a multimeter: when the bus is not used, a resistance of 60ohm should be measured between the two cables (the two 120 ohms terminators in parallel at each side give a global resistance of 120/2=60 ohms).
5. As a useful tool for CAN detection check the Würth CANfinder device.
6. CAN signals could not be present where they should be (i.e. in the OBD2 connector) if a proper setting is not performed on the gateway device.
Interfacing with CAN
In term of circuitry, every device connecting to CAN bus usually interfaces via a CAN Controller, which in turn acceses the bus via a CAN line driver (actually a transceiver).
The CAN controller actually speaks with the device in some way (for example via a serial RS232 interface) and on the other Many manufacturers produce CAN line driver integrated circuits, for example Dallas Semiconductors/MAXIM MAX13050 or Microchip MCP2551.or Philips PCA82C250. or Philips/NXP TJA1054
The following picture shows a generic CAN bus with some devices connected. Proper bus termination should be present at each bus end to damp electric signal reflection (echos). Also it is important to minimize length of the connection between the bus and the transceiver of each connected device (for minimizing undesired echo effects).
Modules are sets of ECUs
In a vehicle, a Module usually identifies a set of two or more Electronic Control Units.
Engine control being the first and most critical, the corresponding Control Units are the most complex. Engine Control Unit (ECU) is supported by Transmission Control Unit (TCU) and the two are sometimes referred as Powertrain Control Module (PCM). Transmission Control Unit, among other things, takes care of gear shift.
User related Electronic Control Units are often referred as a whole with the term Body Control Module or BCM .
Different Networks
The different criticality of the signaling among the vehicle electronic devices, created a push for insulating the networks of different modules, for security needs, but also due to different equipment interfaces being at different speeds.
These different networks are grouped in 3 main classes:
- Body Frame, requiring speeds up to 10Kbps (electric glasses, doors, etc,) [as example of BCM see later references to Peugeot BSI Built-in System Interface]
- Dashboard instrumentation, requiring speed range 50-125Kbps (instrumentation, air conditioning, etc.)
- Engine and powertrain, requiring high speed (up to 1Mbps)
Bus Separation
Engine Control, Airbag, Braking subsystem, Speed control and ABS, are the most safety-critical systems, require high speed, and therefore are usually kept separated from less critical systems.
The separation between the different CAN buses allow much more resilience of the critical systems in the case a noncritical control unit fails (the car engine still starts if you have a problem in the cd-player or in the cabin lights).
Gateways between different networks
In most vehicles, many CAN networks are there, operating at different speed, and that there are gateways allowing data being transferred among the different buses.
The presence of these gateways allow filtered transfer of information, along with eventual speed change. A gateway could act as a firewall allowing only the propagation of specific packets. Gateways are actually electronic devices connected to more than one bus, and can be programmed to allow packet filtering.
There is a interesting specification called Pass-Through SAE J2534-1 which is designed to allow a sort of common protocol (!!vendor and brand independent!!) for traversing in-between bus gateways (CAN and not CAN). This standard should be supported on all vehicles manufactured after 2004. Pass-through specification is targeted to reprogramming and re-flashing of individual electronic control units, but allows also read and write I/O, and periodic messages definition. There is also a set of defined APIs (Application to Program Interfaces) thru which the dialogue can be implemented.
Here is the description of the SAE J2534-1 recommendation document, as taken from http://standards.sae.org/j2534/1_200412/ on sept 22, 2011.
"This SAE Recommended Practice provides the framework to allow reprogramming software applications from all vehicle manufacturers the flexibility to work with multiple vehicle data link interface tools from multiple tool suppliers. This system enables each vehicle manufacturer to control the programming sequence for electronic control units (ECU's) in their vehicles, but allows a single set of programming hardware and vehicle interface to be used to program modules for all vehicle manufacturers. This document does not limit the hardware possibilities for the connection between the PC used for the software application and the tool (e.g., RS-232, RS-485, USB, Ethernet...). Tool suppliers are free to choose the hardware interface appropriate for their tool. The goal of this document is to ensure that reprogramming software from any vehicle manufacturer is compatible with hardware supplied by any tool manufacturer. The U.S. Environmental Protection Agency (EPA) and the California Air Resources Board (ARB) have proposed requirements for reprogramming vehicles for all manufacturers by the aftermarket repair industry. This document is intended to meet those proposed requirements for 2004 model year vehicles. Additional requirements for the 2005 model year may require revision of this document, most notably the inclusion of SAE J1939 for some heavy-duty vehicles. This document will be reviewed for possible revision after those regulations are finalized and requirements are better understood. Possible revisions include SAE J1939 specific software and an alternate vehicle connector, but the basic hardware of an SAE J2534 interface device is expected to remain unchanged."Check also this article by Dan DeMaggio from Drew Technologies: http://www.drewtech.com/support/j2534/intro.html for the story of the development of this SAE recommendation.
Here is an example of a CAN bus dual interface gateway device: the CAN/CAN Gateway CG-ARM7, manufactured by EMS Dr. Thomas Wünsche: http://www.ems-wuensche.com/?menu=_prod&cont=datasheets/html/cgarm7_e
Such a device is indeed a firewall with sophisticated packet content filtering and rewriting capacity.
Here is a document describing a CAN gateway device in a Volkswagen Golf car
The following two paragraphs are taken from http://www.my-gti.com/2296
The role of the Gateway (also known as the Data bus diagnostic interface J533) is the exchange of data between the CAN data bus systems (‘powertrain CAN data bus’, ‘convenience CAN data bus’ and ‘infotainment CAN data bus’) and the conversion of diagnostic data from CAN data bus systems to K-cable and vice versa so the data can be used by vehicle diagnosis, testing and information systems like the dealer VAS tools and Vagcom/VCDS.Here is a picture of the Volkswagen/Audi gateway (part no: 1K0907530AA), taken from http://www.my-gti.com/1101
For various reasons including power drain issues with third generation head units or the addition of new unsupported modules the CAN bus gateway must be upgraded to a newer revision. This guide covers the replacement of the CAN bus gateway in a 2005 MY06 Volkswagen Golf GTI. The upgrade replaces the 1K0 907 530 E (1K0907530E) with a 1K0 907 530 AA (1K0907530AA).
This gateway in Volkswagen terms is called "Data bus diagnostic interface J533". It is used in many car models from this vendor. I found an Audi technical document (from Audi A5 owners group website Audi_A5_-_Networking_en_2.pdf) describing the 4 different version of this gateway component (differences are in terms of its interfaces), for different car models. It is connected to many different buses (different CANs, LIN, MOST). The document states that the "transport mode" can be activated on demand. I guess that this transport mode could allow flow of information between the different buses thru the gateway itself (that in this mode acts somewhat like a router).
Check also this webpage about J533 gateway.
OBD: On Board Diagnostic
Due to the progressive diffusion of electronic devices in the vehicle industry, also diagnostic procedures started to rely on querying these different pieces of electronics, for troubleshooting, and parameter tuning.
The On Board Diagnostic (OBD) standards define how these diagnosis can be performed. Each Control Unit has a set of Diagnostic Trouble Codes (DTC) that can help in identifying its status or eventual failures.
Actual diagnosis is performed by a technician connecting a probing device to a specific plug inside the vehicle, and performing analysis.
In many vehicles, the OBD connector (currently usually compliant to OBD-2 standard) is within reach from the driver seat, and allows access to at least one of the vehicle CAN buses.
Over the years, many different versions of the OBD standard appeared, and the most current one is labeled OBD-2 or OBD-II, which uses a female 16-pin (2x8) SAE J1962 connector on the vehicle. Here is the pinout of its female connector (from wikipedia).
Specific gateway configurations could be needed so to allow specific Electronic Control Units traffic (filtering) to be available on the OBD-2 CAN interface. Also, depending on the manufacturer and model, CAN bus availability on the OBD-2 connector could require a specific configuration elsewhere (maybe jumpers in the circuit breaker panel).
Being present in many vehicles, the OBD-2 connector usually allows access to many diagnostic signals. Sometimes more than one CAN bus is made available on the connector, on different pins.
Here is the pinout of the FIAT OBD-2 connector: http://pinoutsguide.com/CarElectronics/fiat_car_obd_ii_pinout.shtml
Some "rules" about the OBD-2 connector
(info from http://www.auterraweb.com/obdiipinout.html and http://www.obd-ii.de/tech_conn.html )
If pin 5,6,14,16 are connected, the pins 6 and 14 are CAN-HI/LOW (ISO_15765-4 / SAE_J2284), while pin 5 is ground and pin 16 is 12Vcc
If pins 5,7,16 and optionally 15 are connected, the connector supports access to ISO_9141-2 (aka KWP): pin 5 is ground, pin 16 is 12Vcc, pin 7 is ISO-data (aka ISO_K-line), as well as optional pin 15 which is older ISO_9141-2 (aka ISO_L-line).
If pins 2,5,16 are connected, the connector supports access to VPW_J1850: pin 5 is ground, pin 16 is 12Vcc, and pin 2 is VPW-data
If pins 2,5,10,16 are connected, the connector supports access to PWM_J1850: pin 5 is ground, pin 16 is 12Vcc, and pin 2 and 10 are PWM-data
Connector Pins 1,3,8,9,11,12,13 (if connected) are used differently from different vehicle manufacturers, and the OBD-2 standard does not define their role.
Contact usage of some manufacturers (table from http://www.obd-ii.de/tech_conn.html):
| Pin | SAE J1979, ISO 15031 | GM | Fiat | Opel | Saab | Isuzu | GM-LAN since 5.2002 |
|---|---|---|---|---|---|---|---|
| 1 | Manufacturer mandated | second UART | ABS, Brakes, K-Line | reserved | Saab Instruments (+) | SIR (GM8192 Prot.) | SW-LS-CAN (33kB) or DW-FT-CAN (+) (<125kB) |
| 2 | J1850 (+) PWM/VPW | J1850(+) VPW | DW-FT-CAN(+) | n/a | n/a | n/a | n/a |
| 3 | Manufacturer mandated | Comfort | Airbag | K-Line, K2, TCM, Sunroof, CDL, Multi-Timer | n/a | ABS (KW81-Prot.) | MS-CAN (+) (95kB) |
| 4 | Chassis ground | Chassis ground | Chassis ground | Chassis ground | Chassis ground | Chassis ground | Chassis ground |
| 5 | Signal ground | Signal ground | Signal ground | Signal ground | Signal ground | Signal ground | Signal ground |
| 6 | ISO 15765 HS-CAN (+) | PCM | ISO 15765 HS-CAN(+) | Blinkcode | Blinkcode | TCM | ISO 15765 HS-CAN (+) (500kB) |
| 7 | ISO 9141 K-Line | n/a | ISO 9141 K-Line (engine) | K-Line, K1 (engine) | K-Line, K1 (engine) | K-Linie, K1 (engine) | n/a |
| 8 | Manufacturer mandated | CCM | n/a | K-Line, K4 | K-Line (Saab 9000/1, KW81/82 Prot.) | n/a | reserved |
| 9 | Manufacturer mandated | first UART | Body ECU | reserviert | Saab Instruments (-) | ECM/TCM (GM8192 Prot.) | DW-FT-CAN (-) (<125kB) |
| 10 | J1850 (-) PWM | n/a | DW-FT-CAN (-) | n/a | n/a | n/a | n/a |
| 11 | Manufacturer mandated | EVA Controller | (Anti-Theft system) | reserved | L-Line Memory Seats | SIR | MS-CAN (-) (95kB) |
| 12 | Manufacturer mandated | ABS | engine compartment | K-Line, K3, ABS, TC, Steering, RTD, OW | n/a | ABS | K-Line (KW82 Prot.) |
| 13 | Manufacturer mandated | SIR | Luggage compartment | reserved f. K-Line, K5 | n/a | ECM | reserved |
| 14 | ISO 15765 HS-CAN (-) | E&C | ISO 15765 HS-CAN (-) | reserved | n/a | n/a | ISO 15765 HS-CAN (-) (500kB) |
| 15 | ISO 9141 L-Line | n/a | n/a | n/a | n/a | n/a | n/a |
| 16 | Battery Plus, unswitched | Battery Plus, unswitched | Battery Plus, unswitched | Battery Plus, unswitched | Battery Plus, unswitched | Battery Plus, unswitched | Battery Plus, unswitched |
Accessing CAN bus in cars
When CAN bus is not available in the OBD2 plug or it is not feasible to connect to that plug, or if the gateway is not "publishing" the CAN signals on the OBD2 port, the bus can be accessed simply connecting to its wires.
But a disclaimer is needed:
In most cases, car manufacturers are not disclosing the specifications of their diagnostic systems and there are no easy approaches that are consistant across the different brands. Even if you are able to access CAN signals, it will not an easy task to decode and understand the meaning of the data packets. Here is a guide (prepared by uk company Racelogic) in finding the right wires in different vehicles. Devices like the aforementioned Würth canfinder can also be useful.
On Volkswagen Golf cars, the following wire color codes apply (from http://www.my-gti.com/991/performing-repairs-on-can-bus-wiring ). All the three CAN networks use cable pairs, and each pair can be identified by the color of the CAN-HIGH wire, being all the CAN-LOW wires of the same color.
An unshielded two-wire line (1) and (2) with a cross section of 0.35 mm² or 0.5 mm² is used for CAN bus wiring.On FIAT punto diesel, we found a CAN signal in the connector behind the radio. The CAN wires in this car are pink-black and pink-white.
The colour codes of the CAN bus wiring are:
Powertrain CAN high wire Orange/black
Convenience CAN high wire Orange/green
Infotainment CAN high Orange/violet
CAN low wire, (all) Orange/brown
the following link describes a project to interface a car CAN bus to a wifi network:
http://www2.cs.uidaho.edu/~oman/RTCS/Wood-Chroninger-project.pptx
For Peugeot (/PSA and probably for cytroen) cars, check this site: http://peugeot.mainspot.net/ where you can find accurate information and Complete Wiring diagram for Peugeot307, along with information about BSI (Body Control: Built-in System Interface)
Peugeot BSI is connected and "coupled" to Engine Control Unit, and there are protections to avoid tampering by non official dealers or auto-repair technicians. Here are a set of warnings related to Peugeot BSI-ECU maintenance: http://www.liontamer.net/forums/index.php/topic,3.0.html
Here is a picture of a Peugeot BSI.
Peugeot/PSA cars used to implement their own version of CAN bus, called VAN (Vehicle Area Network Comfort data VAN bus / Body Control Data bus). I found some clever guys who did some awesome job in collecting information about VAN: Graham Auld, and Alessandro Zummo. Check http://graham.auld.me.uk/projects/vanbus/index.html and http://code.google.com/p/van-bus/ I got to these sites via this webpage.
Accessing CAN in trucks
Specifically for trucks, there is another standard, to have a uniform access to vehicle data, and targeted for the needs of driving monitoring devices.
This FMS (Fleet Management System) standard is very important for allowing access to specific truck information like the tachometer and odometer, which are needed to be read in the devices to control the driver activity (digital tachographs). FMS requires a SAE J1939 CAN 29-bit 250kbit/sec underlying standard.
For european digital tachographs, check http://www.dtco.vdo.com
In order to be compliant with FMS standard, truck manufacturers implement a specific gateway ECU which reads the informations required by the standard from all the suitable places and thru all the required standard, complying with internal vehicle-brand-specific protocols, and makes all these informations available thru a specific CAN bus to which the tachometer device is connected.
In this way, an FMS compliant digital tachometer devices can be easily connected to any FMS compliant truck.
Different connection cables
(this section needs work and it is partially outdated by what I wrote in the OBD-2 connector section)
A number of different ready made cables exist to access car diagnostics, usually via the aforementioned ODB-2 connector
here is a list of their names, but I am far from understanding their differences
SAE J1850 (can be a dual wire differential 41.6 Kbit/s PWM -Pulse Width Modulation-, or a 10.4Kbit/s VPW singlewire -Variable Pulse Width- ). see this intel document.
SAE J2534 (this is a PWM protocol used in Ford, Lincoln, Mercury, Mazda vehicles)
K-LINE and L-LINE (ISO 9141-2) (to be explained: i need to study)
ISO 14230-4 (also known as KWP)
PWM CAN
HS-CAN (iso 15765)
VAG-COM is not a cable, but a product by Ross-Tech. It is a diagnostic windows software for Volkswagen/Audi. Some cables to be used with this software are labeled VAG-COM
ELM 32x are integrated circuits, (here is elm327 description), sold by elmelectronics.com and based on Microchip Technology Inc. raw devices. These ELM chips act as generic ODB2 decoders and are able to identify and decode many of the different signals available on the ODB2 plug, converting them to RS232, suitable for connection to a PC. Many different PC diagnostic software are capable of interfacing with car electronics via an ELM based adaptor, like this
(To Be fixed)
Arduino and CAN
It is possible to interface an Arduino 2009 board with CAN bus, via a specific CAN shield
I successfully used SkPang Arduino CAN-Bus Shield, to connect to an Audi A6 (2003) and I was able (using the provided sample application) to successfully read RPM (revolutions per minute) data from the engine using a polling mechanism.
This shield uses a MCP2515 CAN controller and a MCP2551 CAN line driver.
Here is a typical configuration of MCP2551
We are currently working on improving the code provided with the shield so to have more sophisticated functions.
Oct 2011 Note: As Rick (in an anonymous comment) said, Sk-Pang shield uses a library taken from Fabien Greif code ( here is the main site: http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek ).The code can be improved, and I hope I will have some time to dedicate to this.
OBDuino
This is a project, started in 2009, to use a custom Arduino-like board to interface to car CAN-Bus and build a
The project is described in this wikipedia page: http://en.wikipedia.org/wiki/OBDuino and the code repository, along with some pictures of prototypes, is in a google-code page, here: http://code.google.com/p/opengauge/wiki/OBDuinoInterface
MPGuino
This project is targeted to build a fuel measurement computer, with an Arduino like device, analyzing the impulses to the fuel injectors, and having tables for calculating the specific fuel injected basing on impulse duration. The signals have to be directly read/taken from the main engine ECU connections to the fuel injectors. Data appears extremely accurate. Here is the link: http://ecomodder.com/wiki/index.php/MPGuino
Teltonika FM4200
This is a device specifically designed to interface with FMS CAN interface in trucks.
I am also testing this device, which uses a NXP LPC2368 microcontroller which is (incidentally) the same uc used by the mbed project. Here is some info about the microcontroller which includes a CAN controller (but not a CAN transceiver). The FM4200 circuits utilizes a Texas Instruments SN65HVD234D 3.3V CAN transceiver. I will write more about this device, as soon as I will have performed more thoroughful tests.
CAN Bus data reverse engineering:
For a Toyota Prius car, by Attila Vass: http://www.vassfamily.net/ToyotaPrius/CAN/cindex.html
For a SAAB car by Tomi Liljemark: http://pikkupossu.1g.fi/tomi/projects/i-bus/i-bus.html
General References and links
The great CAN-CIA site: http://www.can-cia.org/ which is probably the best and more reliable reference site available.
The CAN dictionary: contains a definition of most of the acronyms and abbreviations.
Staffan Nilsson's great page about CAN: http://www.staffannilsson.eu/developer/CAN.htm
Bosch CAN 2.0 specifications.
Mike J Schofield pages: (non working url:
http://www.ixxat.com/can-controller-area-network-introduction_en.html
http://www.jcelectronica.com/articles/CAN%20bus%20tutorial.htm
CAN analysis and equipment vendors
http://www.vector-group.net
http://www.kvaser.com
http://www.ems-wuensche.com : I bought an EMS-Wuensche CPC-USB/ARM7 with galvanic optoinsulation and lowspeed transceiver (TJA1054) for automotive. Received the object (2010.dec.10), and first impression is good: seems very well built and reliable. Will soon test it on the field.
http://www.lawicel.com/
http://www.peak-system.com/
CAN bus in motorcycles
Of course, also motorcycles electronic utilizes digital protocols.
Here is a page about CAN bus in BMW motorcycles.
An affordable and cheap Oscilloscope
Actually I ordered this Rigol DS1052E,
Here are informations about the scope: http://marco.guardigli.it/2011/02/rigol-ds1052e-oscilloscope.html
Software
FreeDiag: http://freediag.sourceforge.net/
FiatECUScan is a software for analyzing Italian made cars (fiat/alfa/lancia branded). Comes in free version and in paid version, with different features. http://fiatecuscan.net. Here is a list of the vehicles supported by current version of FiatECUScan.
FAQ: Q&A
Here are some questions I received by email and the answers I sent.
Q: Is it possible to read value of XXX connecting to the can bus of my car?
A:
As quick answer I would just say that it is not possible.
But this impossibility is normally not due to physical reasons. Each ECU manufacturer uses its own set of rules & codes to craft data packets on their vehicles networks. These informations and data formats are not readily available, and there are no shared rules followed by different manufacturers.
Fm4200 is designed to be able to decode FMS CAN, which is a standard data format representation accepted and shared by all industrial vehicles (trucks). The target is to allow tachometer interconnect with vehicle dashboard.
Tachometers are devices that in many countries MUST be installed on trucks so to monitor driver behavior and work activities. Since there are many tachometer devices, which are built and installed by many countries certified suppliers, a standard was needed, so FMS was born. Non-professional access to tachometer data connection is generally prohibited.
Thru car databus reverse engineering techniques, mostly based on trial and error and/or leaked informations, it is theoretically possible to map some of the CAN data packets to their meanings. Generally read only approach is safe. But problems could arise when vehicle software maintenance is performed, because data packet meaning could change, and current manufacturers are not expected to openly disclose these details.
Write access to the drivetrain and engine bus is to be considered critical and is generally explicitely forbidden or strongly not recommended.
For sure it could be great if all the data was understandable and accessible, but there are important security implications if people irresponsibly tamper with these things. Vehicle security, insurance coverage and road safety could be impacted.
So, be careful and play always on the safe side.
My suggestion is to NEVER connect untrusted devices, unknown or potentially unreliable closed source software to critical systems.
Always study, learn and understand before playing. And always share responsibly your discoveries.
Best,
Marco
------
Marco (@mgua on Twitter)
.

















