OBD-II Data Logging With Raspberry Pi And PiCAN2 CAN Bus Interface Posted by Wilfried Voss on January 04, 2019 In all regularity, I receive inquiries from users attempting to connect their Raspberry Pi with PiCAN CAN Bus interface to their vehicle's OBD-II diagnostics port, and the questions asked prompted me to write down the essentials to. The alternative to a $600 thermocouple data logger? A microcontroller like the Arduino ($25) connected to a Raspberry Pi ($40) running a database and webserver. That means I can charge $535 for brain power and still be competitive;). The Arduino+Raspberry Pi also happens to be an infinitely more powerful system than a thermocouple data logger. Things we’ve tried with our data logger include: Dropping it from a four-storey building; Putting it in a fridge and observing temperature changes; Sending it to the edge of space with a helium balloon; What you will learn. By creating a Sense HAT datalogger with your Raspberry Pi you will learn. I nearly have all Raspberry Pi models in my stuff. I need the one that uses the less amount of power among models that have at least 2 USB ports: a Raspberry Pi B+.Mine is probably comming from Adafruit. This board has 4 USB ports.I only need 2 of them: one for the serial communication, the other for the storage.Its no load consumption is around 1W, the best power consumption for Raspberries.
Step-4:Connecting Temperature Sensor LM35/PT500 with the Arduino
Software Setup
Step 1. Install Debian Linux onto the SD Micro card for the Raspberry Pi: http://elinux.org/RPi_Easy_SD_Card_Setup
Step 2. Make sure you can boot into your Raspberry Pi system (default username/password: pi/raspberry)
Step 3. Change default password:
pi@raspberrypi:~$ passwd [enter] [type your new password]
Step 4. Configure your Raspberry Pi by installing:
Step 5. Upload a program to your Arduino . To help you out, I've made a simple program that logs 6 temperature Just copy/paste into the Arduino IDE and upload to your Arduino device:
/* By Abhishe Bhardwaj IIIT-Jabalpur - December 2013 */ void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue0 = analogRead(A0);
int sensorValue1 = analogRead(A1);
int sensorValue2 = analogRead(A2);
Serial Data Logger Software
int sensorValue3 = analogRead(A3);
int sensorValue4 = analogRead(A4);
int sensorValue5= analogRead(A5);
int outputValue0 = map(sensorValue0, 0, 1023, 0, 255);
int outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
int outputValue3 = map(sensorValue3, 0, 1023, 0, 255);
int outputValue4 = map(sensorValue4, 0, 1023, 0, 255);
Yamaha ypg 535 midi driver. 88 piano-style keys with Graded Soft Touch, matching stand, sustain pedal, USB storage, backlit LCD displays notation and lyrics.
int outputValue5 = map(sensorValue5, 0, 1023, 0, 255);
int outputValue1 = map(sensorValue1, 0, 1023, 0, 255);
//Since I am using LM35 Therefor Temperature=ADC/2
Serial.print(outputValue0/2);
Serial.print(' ');
Serial.print(outputValue1/2);
Serial.print(' ');
Serial.print(outputValue2/2);
![]()
Serial.print(' ');
Serial.print(outputValue3/2);
Serial.print(' ');
Serial.print(outputValue4/2);
Serial.print(' ');
Serial.print(outputValue5/2);
Serial.print('n');
delay(2000);
}
Step 6. Hook up the Temperature Sensor to your breadboard and Arduino:
Step 7. On the Raspberry Pi, make a python program that uses the serial module to read data coming out of the Arduino. The program should then write this data to disk. Something like this should work (name it something like dataLogger.py):
#!/usr/bin/python '' Abhishek Bhardwaj IIIT-Jabalpur This program reads data coming from the serial port and saves that data to a text file. It assumes that the Arduino shows up in /dev/ttyACM0(instead u can use com PORT Number) on the Raspberry Pi which should happen if you're using Debian. '' import serial
import array
ser = serial.Serial(
port=41,
baudrate=9600
# parity=serial.PARITY_ODD,
# stopbits=serial.STOPBITS_TWO,
# bytesize=serial.SEVENBITS
)
#ser.open()
ser.isOpen()
while 1:
command=ser.readline()
temp=command.split()
print(temp)
file=open('Temperature1.dat','a')
file.write('%dn'%int(temp[0]))
file=open('Temperature2.dat','a')
file.write('%dn'%int(temp[1]))
file=open('Temperature3.dat','a')
file.write('%dn'%int(temp[2]))
file=open('Temperature4.dat','a')
file.write('%dn'%int(temp[3]))
file=open('Temperature5.dat','a')
file.write('%dn'%int(temp[4]))
file=open('Temperature6.dat','a')
file.write('%dn'%int(temp[5]))
file.close()
python program to log data (note: I suggest you run this program within screen so that you can do other things with your Raspberry Pi while it's collecting data):
Step 11. Use Gnuplot (which was installed in step 4.5) to make a graph of the data. To do this, make a small gnuplot script (call it something like plotData.plt):
reset
set term wxt enhanced set autoscale xy set timefmt '%Y-%m-%d %H:%M:%S' set format x '%b %d %H:%M' set style data line set xlabel ' set ylabel 'Temperature (C)' plot 'Temperature1.dat','Temperature2.dat','Temperature3.dat','Temperature4.dat','Temperature5.dat','Temperature6.dat' set output 'data.png' set key left
and make the graph using:
This will make the file 'data.png'.
Step 12. Move the file data.png into your web server directory, which defaults to /var/www/
This can be set up in a shell script and run automatically using cron.
********************************************************************************************************************************************
In this tutorial we will see how to use the serial port on Raspberry Pi. We will use the serial port available on Raspberry with a RS232/TTL 3-5,5V adapter and a USB-serial adapter. By default the Raspberry Pi’s serial port is configured to be used for console input/output. This can help to fix problems during boot, or to log in to the Pi if the video and network are not available.
To be able to use the serial port to connect and talk to other devices (e.g. a modem a printer. ), the serial port console login needs to be disabled.
Here we use Raspberry Pi 2, and we connect a RS232/TTL 3-5,5V adapter to pins 4 (5V), 6 (GND) ,8 (TX),10 (RX) of Raspberry, obviously connect tx with rx and vice versa.
To search for available serial ports we use the command
The output is something like this
Last line indicates that the console is enabled on the serial port ttyAMA0, so we disable it
Run the configuration command and follow the instructions below
Reboot and try with
output now is
Now we can use the serial ttyAMA0. We connect an adapter usb / serial, then we will try to establish a communication between the two serial ports; obviously in a practical application to every serial we could connect a device, for example a modem, a printer a RFID reader etc.
After connecting the second serial port we launch the command to find the name that Raspberry gives him
The output is something like this
Ok, now we create two files, one who writes something on the ttyAMA0 port and the other that reads on the ttyUSB0 port.
serial_write.py
serial_read.py
If we run both files, serial_read.py will read what serial_write.py writes
This is just a small example but it can serve as a starting point to send a print to an old printer or read data from a router or a gps.
Follow us on social to stay informed.
http://www.emmeshop.eu Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |