lithiumate lite bms raspberry pi interface...
TRANSCRIPT
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
1/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
Lithiumate Lite BMS Raspberry Pi Interface Design Aim: To monitor/query BMS stats from a handheld WiFi device such as an iPhone or a video head unit.
Peter Chave ([email protected]), Revision 0.3 – 2/10/2013
EV project: www.stealthbus.net
Revision History Revision 0.1 – Initial beta, using php script to directly exec serial reader.
Revision 0.2 – Re-written using background process to poll BMS and render html.
Revision 0.3 – Cleaned up error reporting, added head unit output.
Contents
1 Access Lithiumate Lite BMS data on handheld WiFi device. .................................................. 2 1.1 System description .................................................................................................................................. 2 1.2 On-line simulation .................................................................................................................................... 2 1.3 Hardware overview .................................................................................................................................. 2 1.4 Software structure ................................................................................................................................... 3 1.5 Web page structure: ................................................................................................................................ 3
2 User interface .............................................................................................................................. 4 2.1 Description .............................................................................................................................................. 4 2.2 Common elements .................................................................................................................................. 4 2.3 Main summary screen ............................................................................................................................. 5 2.4 Navigation to sub pages .......................................................................................................................... 5 2.5 Charging information page ...................................................................................................................... 6 2.6 Voltage history ......................................................................................................................................... 6 2.7 Amp history ............................................................................................................................................. 7 2.8 Per cell voltage graph page .................................................................................................................... 7 2.9 Per cell temperature graph page ............................................................................................................. 8 2.10 Troubleshooting ....................................................................................................................................... 9
3 How to build it ........................................................................................................................... 10 3.1 Hardware required: ................................................................................................................................ 10 3.2 Easy configuration ................................................................................................................................. 10 3.3 Manual configuration steps ................................................................................................................... 10
4 Modifying install ....................................................................................................................... 13
5 Head unit display ...................................................................................................................... 14
6 Future improvements ............................................................................................................... 14
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
2/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
1 Access Lithiumate Lite BMS data on handheld WiFi device.
1.1 System description
A Raspberry Pi (ARM based credit card size computer) is connected to the USB port of the Lithiumate Lite BMS.
The Raspberry Pi (RPi) using a WiFi adapter acts as a hotspot with simple web server. The handheld WiFi device
via its web browser connects to the hotspot accesses a simple HTML/Javascript page. The main page in turn
retrieves a data page which is being generated by a background helper program on the RPi. The helper
program queries the BMS and generates javascript data which then polled by the client and processed by the
browser to render the BMS status information to the user.
Example screen shot:
1.2 On-line simulation
A simulation of the interface look and feel can be viewed on any browser including iPhone.
http://www.stealthbus.net/bmssim/bms.html
1.3 Hardware overview
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
3/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
Lithiumate BMS is connected via a standard USB cable to USB port on the Raspberry Pi.
A USB WiFi adapter is connected to the second USB port on the RPi.
A WiFi connection is established to the handheld device.
1.4 Software structure
Raspberry Pi running Wheezy (standard distro).
Software installed: apache2 + hostapd + udhcpd + helper program (written in C)
1.5 Web page structure:
Main page is “index.html”, containing basic page layout and javascript rendering routines. On the main page
there is a hidden embedded ‘iframe’, this is used to poll for new values without requiring a full page reload.
The iframe source is a page called bmsdata.html
The background program (bmsd) sends an “x”, “v” and “t” on the serial port for device (default: /dev/ttyUSB0).
The hex string returned from the BMS is parsed into the javascript variables written to the file called
bmsdata.html. At the end of the page returned is call to main page to invoke rendering of the data.
In my system a second iframe is used to query in the background the status of the auxiliary battery and
optionally other analog measurements, if this module is not present, the entry is simply left blank in the
rendered GUI. In a future version I would like to integrate this directly on the RPi (and avoid the 2nd device.)
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
4/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
2 User interface
2.1 Description
The UI is accessed by connecting to the RPi hotspot, and opening a browser to IP address of the RPi.
The page is designed for iPhone usage as mobile application, the first time you access it from safari, if you
select “link to home screen”. A link is placed on the home screen, so the page can be launched just like a native
app. This is nice as it clears the screen of the browser controls.
2.2 Common elements
Tally toggles on and off every 5s. Overall status: NORMAL, WARNING, FAULT or CONNECT ISSUE
Detailed status: Contains description of fault or warning message from BMS
The banners are colored green for OK, yellow for WARNING and red for FAULT. The text on the top banner
changes accordingly. The lower banner displays the warning/fault message from the BMS.
In case of communication issues with BMS, the banner will be colored blue, with the specific error code
displayed in the detailed status area.
A tally is displayed in the upper bar toggling on and off to show that the background task is running. If this does
not toggle, but the page is refreshing normally then an error condition exists with that task.
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
5/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
2.3 Main summary screen
State of Charge Pack Voltage (min hold) Pack Amps (peak hold)
Aux Battery* Current Cell Min V (hold min : cell ID) Current Cell Max Temp (hold max : cell ID)
*Note on “Aux Battery” reading, this is read from another device in the car. I have a small IP connected PIC
board with 12 channels of ADC. Via a page query the voltage is returned. In a system without that module, the
entry will appear blank. You can easily edit the page to remove it or replace it with another parameter if you
desire.
2.4 Navigation to sub pages
The page interface is designed for a touchscreen; the following areas launch subpages.
Charging information Pack volts history Pack amps history Returns to main page
Per cell voltage graphs Per cell temperature graphs
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
6/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
2.5 Charging information page
State of Charge Estimated recharge time (at this rate)
Total power required to recharge Estimated cost Estimated recharge time (at this rate)
2.6 Voltage history
Graph scrolls automatically every 5s, complete window shows approximately last 5 minutes. Range is
controlled from the index.html page.
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
7/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
2.7 Amp history
Graph scrolls automatically every 5s, complete window shows approximately last 5 minutes. Range is
controlled from the index.html page.
2.8 Per cell voltage graph page
Range of graph and coloring options can be controlled by editing the header of the index.html page.
Tapping the graph toggles between the current values and the lowest recorded per cell view.
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
8/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
2.9 Per cell temperature graph page
Range of graph and coloring options can be controlled by editing the header of the index.html page.
Tapping the graph toggles between the current values and the highest recorded per cell view:
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface
9/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
2.10 Troubleshooting
Fault Likely cause Remedy
Unable to open web page Not connected to host
spot
Check WiFi settings, hotspot
default name is “RPi-BMS”
IP address not set
(DHCP issue)
Test by manually setting IP to
10.1.1.100 / 255.255.255.0
Web server issue Verify apache2 is running and
pages are present in /var/www
Status = “CONNECT ISSUE”, Detailed =
“Unable to open /dev/ttyUSB0”
BMS is not connected Connect BMS to USB port on RPi.
BMS is assigned to
another serial port
Look in /dev and for ttyUSB
entries. Adjust /etc/init.d/bmsd
to match.
Status = “CONNECT ISSUE”, Detailed =
“timeout (x)”
BMS is not powered Turn on ignition or connect AC.
Tally light does not toggle, and status
is not updating
Background task bmsd
is not running
Check running status by “ps –A |
grep bmsd”. Manually start bmsd
and look for error messages
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface 10/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
3 How to build it
3.1 Hardware required:
Component Cost Example(s)
Raspberry Pi $35 http://www.alliedelec.com/lp/120626raso/ http://www.mcmelectronics.com/product/83-14421&scode=GS401&CAWELAID=1599056700?catargetid=1545764029&cagpspn=pla&gclid=COjs9I_517QCFQeynQodOHoA-g
2G (or bigger) SD Card $5-10 http://www.amazon.com/Transcend-Class-Flash-Memory-TS4GSDHC10E/dp/B003VNKNE6/ref=sr_1_2?ie=UTF8&qid=1357759410&sr=8-2&keywords=4gb+sd+card+class+10
USB WiFi $10 http://www.amazon.com/gp/product/B005CLMJLU/ref=olp_product_details?ie=UTF8&me=&seller=
Enclosure $10-20 http://www.amazon.com/gp/product/B008TCUXLW/ref=oh_details_o00_s00_i00
PSU Car 12v - USB 1A $5-10 http://www.amazon.com/2-Port-Charger-Samsung-Victory-Android/dp/B0062D7SR2/ref=pd_sim_sbs_e_4
Total $65-85
3.2 Easy configuration
1. Download the following image on your PC, this is a pre-configured image. It contains the 2012-12-16-
wheezy-raspbian image with apache2, php, hostapd, udhcpd and the custom web pages all ready to go.
http://www.stealthbus.net/src/RPi-image-r0.2.zip
a. Out of the box this image assumes you are using the Edimax USB WiFi, if you used another, you
will need to tweak the driver in the /etc/hostapd/hostapd.conf file.
2. Follow the standard image transfer procedure here, using the prepackaged image you downloaded:
http://www.raspberrypi.org/downloads
3. Insert the SD card into the RPi, connect WiFi USB, the USB cable to BMS and power cable.
4. On your WiFi device, connect to SSID: RPi-BMS (access code is 87654321)
5. Open a browser and point it at http://10.1.1.1
3.3 Manual configuration steps
1. Install standard Raspbain “wheezy” image using instructions here:
http://www.raspberrypi.org/downloads
2. Connect Raspberry Pi (RPi) to HDMI monitor, USB keyboard, internet connection (using on board LAN
port), and WiFi adapter.
3. Power up and at the initial configuration page preform basic configuration
a. Select “expand_rootfs”, so you have full access to the disk.
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface 11/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
b. Select “boot_behaviour” mode option, select “No” for “Should we boot straight to desktop?”
c. Select “Finish”, and answer “Yes” to “Would you like to reboot now”.
4. Once the Pi reboots, login as “pi”, password is “raspberry”.
Install the following packages:
sudo apt-get install apache2 hostapd udhcpd
5. Configure DHCP, modify the following lines in /etc/udhcpd.conf (comment out all others)
start 10.1.1.2
end 10.1.1.20
interface wlan0
remaining yes
opt subnet 255.255.255.0
opt lease 86400
6. Comment out the following line in /etc/default/udhcpd
#DHCPD_ENABLED="no"
7. Modify/add the following to /etc/network/interfaces
allow-hotplug wlan0
iface wlan0 inet static
address 10.1.1.1
netmask 255.255.255.0
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
If your WiFi adapter is natively supported by hostapd in RPi wheezy distro you go on the next step.
If not, like me and you used the EDIMAX EW-7811Un while being the most compact and requires no
external power on the RPi, you will need to recompile hostapd to support this adapter:
Credit: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=46&t=25921
Note: Do not remove the existing copy of hostapd, just compile the new version and swap the bin file.
This is the updated driver “RTL8192xC_USB_linux_v3.4.4_4749.20121105.zip” which can be
downloaded from here:
http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=1&PNid=21&PFid=48&Level=5&
Conn=4&DownTypeID=3&GetDown=false&Downloads=true
Copy zip file to RPi.
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface 12/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
unzip RTL8192xC_USB_linux_v3.4.4_4749.20121105.zip
cd RTL8192xC_USB_linux_v3.4.4_4749.20121105/wpa_supplicant_hostapd
unzip wpa_supplicant_hostapd-0.8_rtw_20120803.zip
cd wpa_supplicant_hostapd-0.8/hostapd
make
sudo make install
sudo cp /usr/local/bin/hostapd /usr/sbin/hostapd
sudo cp ../../rtl_hostapd_2G.conf /etc/hostapd/hostapd.conf
8. Modify the following entries in /etc/hostapd/hostapd.conf
Note: You can you any SSID name you like here.
ssid=RPi-BMS
9. Modify this line in /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
10. Download web page package and install in files
sudo wget “http://www.stealthbus.net/src/RPi-bmsgui-r0.2.tgz” sudo tar –zxvf RPi-bmsgui-r0.2.tgz
sudo cp bin/bmsd /usr/sbin/bmsd
sudo cp init.d/bmsd /etc/init.d/bmsd
sudo update-rc.d bmsd defaults
sudo cp –r www/* /var/www
11. Enable services to start at boot up
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable
sudo update-rc.d bmsd enable
12. Connect the Lithiumate BMS USB port to the RPi.
13. Reboot RPi
14. Verify install, On your WiFi device, connect to SSID: RPi-BMS (access code is 87654321)
15. Open a browser and point it at http://10.1.1.1
Credits: Hotspot setup adapted from: http://elinux.org/RPI-Wireless-Hotspot
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface 13/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
4 Modifying install Edit the following file: /etc/init.d/bmsd
The script takes two parameters, the first is the serial port and second is the number of cells in the battery
pack.
You may want to tweak or add things, like change the graph ranges, warning color limits, etc.
Most GUI modification can be achieved by editing the index.html file located in /var/www
At the top of the file is a control parameter section with the key values, simply edit, save and refresh the
browser on the hand held for the new behavior to take effect.
//*************************************************************************************************************
// Modify this section to change GUI behavior to suit your application
//*************************************************************************************************************
// Limits of voltage graph (Y-axis)
var MAX_GRAPH_V = 4.0
var MIN_GRAPH_V = 2.0
// Color thresholds, beyond MIN/MAX color is red, between MIN-LO or MAX-HI color is yellow, else bar is green.
var MAX_CELL_V = 3.8
var HIGH_CELL_V = 3.6
var LOW_CELL_V = 2.9
var MIN_CELL_V = 2.7
// Limits of temperature graph (Y-axis)
var MAX_GRAPH_T = 60
var MIN_GRAPH_T = 0
// Color thresholds, beyond MIN/MAX color is red, between MIN-LO or MAX-HI color is yellow, else bar is green.
var MAX_CELL_T = 50
var HIGH_CELL_T = 40
var LOW_CELL_T = 5
var MIN_CELL_T = 0
// Cost per charge calculations
var PACK_CAPACITY_KWH = 16
var COST_PER_KWH_CENTS = 8
var CHARGE_RATE_1_TEXT = "120v:12A"
var CHARGE_RATE_1_KW = 1.44
var CHARGE_RATE_2_TEXT = "240v:24A"
var CHARGE_RATE_2_KW = 5.76
//*************************************************************************************************************
If you want other parameters or change the query process the source code for the readbms is included in the
tarball. Simple edit the bms.c (in the ~/src directory) and then recompile using:
gcc –o bms bms.c
service bmsd stop
sudo cp bms /usr/sbin/bmsd
service bmsd start
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface 14/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx
5 Head unit display If you have a head unit you can configure the RPi to output a video signal, which
Since the head unit will be a uni-directional interface, an optional version of page is created. “headunit.html” in
my version I reduce the horizontal size so it displays nicely.
Make midori open by default when X starts and make the page fullscreen.
/etc/xdg/lxsession/LXDE/autostart
@midori -e Fullscreen -a http://127.0.0.1/headunit.html
Disable screen blanking:
/etc/lightdm/lightdm.conf
[SeatDefaults]
xserver-command=X -s 0 dpms
This was adapted from: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=41&t=924&start=25
6 Future improvements In no specific order, ideas to add or enhance design:
- Integrate aux battery monitoring onto RPi board.
o Using possibly this module: http://www.abelectronics.co.uk/products/3/Raspberry-Pi/17/ADC-
Pi-V2---Raspberry-Pi-Analogue-to-Digital-converter
- Export logging data ( via browser ‘file download’ )
- Make configuration parameters modifiable via the web GUI.
- Add either LCD or LED display to show charging status externally from the car (so at public charging
stations people can see if my car is charged before unplugging).
Thanks for your interest.
Peter Chave ([email protected])
EV Project: www.stealthbus.net
Author:
Peter Chave
Revision 0.2 (1/28/2013) Created: 6/17/2013 4:16:00 PM Changed: 6/17/2013 4:16:00 PM
Printed: 6/17/2013 4:17:00 PM Title:
Lithiumate Lite BMS Raspberry Pi Interface 15/15
D:\Chi Projects\DugBus\Battery Management\Access Lithiumate Lite BMS data on handheld WiFi device-r0.3.docx