Popular Post euc Posted August 21, 2016 Popular Post Share Posted August 21, 2016 (edited) I just created a neat Arduino library to interface EUCs via Bluetooth or directly via the tx/rx connection of the motherboards. I have tested it with several older Gotway EUCs and I will try to add support for the newer Gotway protocol and also for the older King Song protocol. You can download the library on Github: https://github.com/T-vK/Electric-Unicycle-Interface I mainly wrote this for two main reasons: I wanted to make some cool LED effects like rotating LEDs at the precise speed of the Unicycle. To make a DIY Bluetooth smartwatch that displays the speed, battery status etc. The first one is ready to go as you can see in this video: A first prototype of the second one is sort of ready: Here is an example of how you can interface the EUC using my library: /* Simply receive the data the electric unicycle sends * and print it to the serial console on your PC. */ #include <SoftwareSerial.h> #include <EucInterface.h> //Bluetooth serial with rx on pin 9 and tx on pin 10 SoftwareSerial BluetoothSerial(9,10); Euc Euc(BluetoothSerial, BluetoothSerial); // Receive and transmit data via bluetooth void setup() { Serial.begin(250000); // We'll use the normal hardware serial to print out all the received data BluetoothSerial.begin(9600); // Most unicycles communicate @9600 baud over bluetooth Euc.setCallback(eucLoop); // Set a callback function in which we can receive all the data the unicycle sends } void loop() { Euc.tick(); // This simply needs to be called regularely } void eucLoop(float voltage, float speed, float tempMileage, float current, float temperature, float mileage, bool dataIsNew) { if (dataIsNew) { // new data received Serial.print("Voltage: "); Serial.print(voltage); Serial.println("V"); Serial.print("Current: "); Serial.print(current); Serial.println("A"); Serial.print("Speed: "); Serial.print(speed); Serial.println("km/h"); Serial.print("Total mileage: "); Serial.print(mileage,3); Serial.println("km"); Serial.print("Temp mileage: "); Serial.print(tempMileage,3); Serial.println("km"); Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" deg Celsius"); Serial.println(""); Serial.println(""); } } This example uses the Bluetooth interface of the Unicycle. So you'll need a serial Bluetooth module for it. I highly recommend the HC-05 which can be found for less then 3 US$ on aliexpress. But don't worry, there are plenty of other examples in my repo: https://github.com/T-vK/Electric-Unicycle-Interface/tree/master/examples API docs Euc(ReceiverSerial, TransmitterSerial); //create new instance of this class Euc.tick(); // simply has to be called regularly Euc.setCallback(callbackFunction); // you have to specify a callback function to which the class can send the data it receives from the unicycle //Example callback function: void callbackFunction(float voltage, float speed, float tempMileage, float current, float temperature, float mileage, bool dataIsNew) { // Do something with the received data } Euc.beep(); // make the unicycle beep Euc.maddenMode(); // set it to madden mode Euc.comfortMode(); // set it to confort mode Euc.softMode(); // set it to soft mode Euc.calibrateAlignment(); // calibrate alignment Euc.disableLevel1Alarm(); // disable level 1 alarm Euc.disableLevel2Alarm(); // disable level 2 alarm Euc.enableAlarms(); // enable alarms Euc.enable6kmhTiltback(); // enable 6km/h tiltback Euc.disable6kmhTiltback(); // disable 6km/h tiltback Edited August 31, 2016 by euc 2 10 Quote Link to comment Share on other sites More sharing options...
Popular Post euc Posted August 22, 2016 Author Popular Post Share Posted August 22, 2016 (edited) Proof of concept of receiving the data using an Arduino, an HC-05 module and an 0.96" OLED display. Here's the code: /* Receive the data the electric unicycle sends * and print it to an OLED display. */ #include <math.h> #include <SoftwareSerial.h> #include <EucInterface.h> #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> //Bluetooth serial with rx on pin 9 and tx on pin 10 SoftwareSerial BluetoothSerial(9,10); Euc Euc(BluetoothSerial, BluetoothSerial); // Receive and transmit data via bluetooth Adafruit_SSD1306 display(4); // 4 = OLED_RESET void setup() { BluetoothSerial.begin(9600); // Most unicycles communicate @9600 baud over bluetooth Euc.setCallback(eucLoop); // Set a callback function in which we can receive all the data the unicycle sends display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) display.clearDisplay(); display.setTextColor(WHITE); } void loop() { Euc.tick(); // This simply needs to be called regularely } void eucLoop(float voltage, float speed, float tempMileage, float current, float temperature, float mileage, bool dataIsNew) { if (dataIsNew) { // new data received display.clearDisplay(); display.setCursor(0,0); display.setTextSize(2); display.print(abs((int)speed)); display.println(" km/h"); display.setTextSize(1); display.print("Mileage: "); display.print(mileage,3); display.println(" km"); display.print("Temperature: "); display.print(temperature); display.println(" C"); display.display(); } } Edited September 2, 2016 by euc 4 Quote Link to comment Share on other sites More sharing options...
esaj Posted August 22, 2016 Share Posted August 22, 2016 (edited) Very nice work! If you want to make it work with older King Songs, here are the differences in protocol (namely, the KS board doesn't seem to send the second header & odometer data, plus the first byte of the header is 0x00 instead of 0x04): Edited August 23, 2016 by esaj 3 Quote Link to comment Share on other sites More sharing options...
euc Posted August 22, 2016 Author Share Posted August 22, 2016 Oh, that's very interesting. I'll definitely add support for more EUCs to the library when I have some more time. I'll analyze the protocol of an mcm4 in a week or two btw. 1 Quote Link to comment Share on other sites More sharing options...
euc Posted August 22, 2016 Author Share Posted August 22, 2016 Let's see how small I can make it. 1 Quote Link to comment Share on other sites More sharing options...
esaj Posted August 22, 2016 Share Posted August 22, 2016 4 minutes ago, euc said: Let's see how small I can make it. I recognize the other stuff, but what is that board between the battery and Pro Mini? Buck/boost converter or small lithium BMS? Is that a 9V battery or lithium cell? I ordered a bunch (like 10 or something) of those Pro Minis, only to find out that they're really not that handy in the end The space saving vs. Nano is negligible, especially after soldering the row connectors on it, as well as the price difference, so I'll probably stick with Nanos. 1 Quote Link to comment Share on other sites More sharing options...
euc Posted August 22, 2016 Author Share Posted August 22, 2016 4 minutes ago, esaj said: I recognize the other stuff, but what is that board between the battery and Pro Mini? Buck/boost converter or small lithium BMS? Is that a 9V battery or lithium cell? I ordered a bunch (like 10 or something) of those Pro Minis, only to find out that they're really not that handy in the end The space saving vs. Nano is negligible, especially after soldering the row connectors on it, as well as the price difference, so I'll probably stick with Nanos. Yes, it's a step up converter to go from ~3.7V to 5V. I'll add add one of these cheap charging boards some time in the future. The lipo is a simple 3.7V battery. And I totally agree that the pro minis really aren't very small. But I have a ton of them lying around and they operate at 5V. For 3.3V projects I really recommend the ESP8266. They have much better specs than Arduinos, they are half the size, they have Wifi built it and they only cost like 2 bucks a piece. They can also be programmed with the Arduino IDE and you can also flash a custom firmware which allows you to write your whole code in Lua which makes coding like 10 times easier. It's even possible to upload your code OTA, which is ridiculously awesome. Downside is that they only operate at 3.3V. (Although if you get a logic level converter nothing would stop you from using it in a 5V project) Atm I'm waiting for the ESP32 (which comes out in 10 days). It's basically like an ESP8266, but the specs are much higher and it also has Bluetooth built in. That thing will hopefully replace the bulky combination of a pro mini and an HC-05. 1 Quote Link to comment Share on other sites More sharing options...
Keith Posted August 22, 2016 Share Posted August 22, 2016 4 hours ago, esaj said: Very nice work! If you want to make it work with older King Songs, here are the differences in protocol (namely, the KS board doesn't seem to send the second header & odometer data, plus there's an extra 0x00 -byte in front of the header): Ah thank you @esajand @euc, the lack of an odometer and IOS app for my older KingSong have always been a bit of a pain and I can't be bothered to carry an Android phone with me as well. You have, between you now got the cogs whirring in what passes for my brain........ Now can I tap the USB power supply in my KS-14, fit the electronics inside (no problem at all I've got an empty battery bay) and have both speed (or possibly Watt hours consumed) and total mileage displayed actually on the wheel, relying on the Arduino to keep the odometer running total. It has got to be worth trying hasn't it? 1 Quote Link to comment Share on other sites More sharing options...
euc Posted August 22, 2016 Author Share Posted August 22, 2016 (edited) 12 minutes ago, Keith said: Ah thank you @esajand @euc, the lack of an odometer and IOS app for my older KingSong have always been a bit of a pain and I can't be bothered to carry an Android phone with me as well. You have, between you now got the cogs whirring in what passes for my brain........ Now can I tap the USB power supply in my KS-14, fit the electronics inside (no problem at all I've got an empty battery bay) and have both speed (or possibly Watt hours consumed) and total mileage displayed actually on the wheel, relying on the Arduino to keep the odometer running total. It has got to be worth trying hasn't it? I'm not sure if it would be a good idea to draw power from the built in 12/5V supply. You might fry it if you draw too much current from it... I found really cheap DC converters that can go from 24V-72V To 12V. They are like 7 US$. I'd get one of those and a 12V to 5V step down converter. Edited August 22, 2016 by euc 1 Quote Link to comment Share on other sites More sharing options...
euc Posted August 23, 2016 Author Share Posted August 23, 2016 16 hours ago, esaj said: I got "back" to electronics only recently (well, actually since last November or so), but I did have some education in electricity / electronics over a decade ago. Still, I'd say I've learned more within these last 9-10 months or so than back then at school in a few years I always really liked taking broken electronics apart and trying to fix them. But it was usually just fixing solder connections or replacing a capacitor. I think I really started getting into Arduinos, sensors and all that fun stuff maybe a year ago. And yeah the education about electronics that I received in school was pretty useless. I soldered the parts together and added a switch between the lipo and the boost converter. I also used wires instead of PCB to reduce thickness. But I'm not too happy with the results: It looks like a mess... It's 17mm in thickness btw. When I have some more time I will probably 3d print a nice enclosure for the thing and add straps to it, so that I can actually wear it without making everyone think I'm a terrorist. 1 Quote Link to comment Share on other sites More sharing options...
esaj Posted August 24, 2016 Share Posted August 24, 2016 @euc @Battling Split off the off-topic stuff (started by me, my fault, again ) to here: Sorry for the thread-hijack. Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted August 24, 2016 Share Posted August 24, 2016 Great work @euc!! I did something similar, I think - please see here: https://github.com/EGG-electric-unicycle/documentation/wiki/MicroWorks-30B4-controller-board-RGB-LED-strip 2 Quote Link to comment Share on other sites More sharing options...
euc Posted August 24, 2016 Author Share Posted August 24, 2016 (edited) 17 minutes ago, electric_vehicle_lover said: Great work @euc!! I did something similar, I think - please see here: https://github.com/EGG-electric-unicycle/documentation/wiki/MicroWorks-30B4-controller-board-RGB-LED-strip That's awesome! I'm a bit jealous that your motherboard sends updates every two milliseconds. Mine is only sending it every 200ms... I see you're using current measurements instead of detecting negative acceleration for the break light. I wonder what the advantages are. Edited August 24, 2016 by euc 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted August 24, 2016 Share Posted August 24, 2016 My code is very simple because I did it fast as my focus is to make an OpenSource firmware for MicroWorks 30B4 boards, as that company sell for DIY every part of an EUC. That's an error, is also 200ms, see here more details: https://github.com/EGG-electric-unicycle/documentation/wiki/MicroWorks-30B4---30km-h-controller-board-with-bluetooth 2 Quote Link to comment Share on other sites More sharing options...
euc Posted August 24, 2016 Author Share Posted August 24, 2016 1 hour ago, electric_vehicle_lover said: My code is very simple because I did it fast as my focus is to make an OpenSource firmware for MicroWorks 30B4 boards, as that company sell for DIY every part of an EUC. That's an error, is also 200ms, see here more details: https://github.com/EGG-electric-unicycle/documentation/wiki/MicroWorks-30B4---30km-h-controller-board-with-bluetooth Very interesting! I have a question about the "Battery voltage and power" list. I was planning to create something similar, but I wasn't sure if it would make any sense. What if the battery is very old and has been charged a few hundred times? Wouldn't the results differ quite a lot? And what if you have two battery packs in parallel? Would that make a difference? Or what if the li-ion cells are from a different manufacturer? 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted August 24, 2016 Share Posted August 24, 2016 Go and tell all of that possibilities to the board firmware!! :-) " When the power available is 20% or less, the board will beep (even when the motor is stopped)." We need to simplify and not get more possibilities. 1 Quote Link to comment Share on other sites More sharing options...
esaj Posted August 24, 2016 Share Posted August 24, 2016 8 minutes ago, euc said: Very interesting! I have a question about the "Battery voltage and power" list. I was planning to create something similar, but I wasn't sure if it would make any sense. What if the battery is very old and has been charged a few hundred times? Wouldn't the results differ quite a lot? And what if you have two battery packs in parallel? Would that make a difference? Or what if the li-ion cells are from a different manufacturer? Personally, I'd prefer to simply see the voltage reading than any percentage-value, but that's just me... It's pretty much the "leading" health-indicator of the batteries, as well as charge-state, but for "pure layman", reading the values and dips in voltage might be a bit too much, and they prefer simple 0-100% display instead. The difference between new and old batteries is mostly how much charge they store and how fast they get empty, ie. you just see the voltage/percentages dropping faster (and likely larger fluctuations in voltage/percentage between braking/acceleration, especially towards the end of the charge). 1 Quote Link to comment Share on other sites More sharing options...
euc Posted August 24, 2016 Author Share Posted August 24, 2016 1 hour ago, electric_vehicle_lover said: Go and tell all of that possibilities to the board firmware!! :-) " When the power available is 20% or less, the board will beep (even when the motor is stopped)." We need to simplify and not get more possibilities. I was just trying to say that I could imagine different batteries to have a different percentage left when outputting the same voltage. 1 hour ago, esaj said: The difference between new and old batteries is mostly how much charge they store and how fast they get empty, ie. you just see the voltage/percentages dropping faster (and likely larger fluctuations in voltage/percentage between braking/acceleration, especially towards the end of the charge). Okay that's good to know. But there would still be the manufacturer problem. According to these graphs, it's safe to say that you couldn't properly predict the available capacity in percent just by reading the voltage:http://www.candlepowerforums.com/vb/showthread.php?257543-LiIon-18650-battery-comparison But I don't know if the same would happen with battery packs behind a bms. 1 hour ago, esaj said: Personally, I'd prefer to simply see the voltage reading than any percentage-value, but that's just me... It's pretty much the "leading" health-indicator of the batteries, as well as charge-state, but for "pure layman", reading the values and dips in voltage might be a bit too much, and they prefer simple 0-100% display instead. Personally, I'd prefer an estimate of how many kilometers I can ride until the battery is empty. 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted August 24, 2016 Share Posted August 24, 2016 5 minutes ago, euc said: Personally, I'd prefer an estimate of how many kilometers I can ride until the battery is empty. Technology is not there yet. I think users, currently prefer actual technology state for the current relative cheap price of EUCs. But seems that a raw estimation could be possible, since odometer value and battery state values are available. There is one thing, there is no persistent memory on the board which I think is need for implement such feature. 1 Quote Link to comment Share on other sites More sharing options...
esaj Posted August 24, 2016 Share Posted August 24, 2016 8 minutes ago, electric_vehicle_lover said: Technology is not there yet. I think users, currently prefer actual technology state for the current relative cheap price of EUCs. But seems that a raw estimation could be possible, since odometer value and battery state values are available. There is one thing, there is no persistent memory on the board which I think is need for implement such feature. If using Arduino or such "in-between" (like @euc is), there's some EEPROM available. The estimation is a bit hard, as you get "less" charge out of the battery with different riding conditions (ie. higher currents), as more of it will burn off as heat in the packs themselves, and won't be "visible" to the mainboard & the Arduino reading the data. Seemingly less capacity is got out from the pack with higher discharge (C) -rates, but when charging, you still end up finding out that the battery takes a full charge (more Wh/Ah than seemingly came out of the pack). Energy doesn't disappear, but the "outside" device measuring the capacity doesn't "see" the energy burned off by the pack (wasted power = current * internal voltage drop of the pack due to internal resistance). 1 Quote Link to comment Share on other sites More sharing options...
euc Posted August 24, 2016 Author Share Posted August 24, 2016 (edited) 16 minutes ago, electric_vehicle_lover said: Technology is not there yet. I think users, currently prefer actual technology state for the current relative cheap price of EUCs. But seems that a raw estimation could be possible, since odometer value and battery state values are available. There is one thing, there is no persistent memory on the board which I think is need for implement such feature. Technically, you just need a valid "voltage"/"percent" list for the euc you are riding. Then you could simply time how long it takes to drop by one percent and how far you got during that period. Then it's just a matter of extrapolating. The downside would obviously be that you have drive a few meters before an estimate can be calculated. But the upside is that you don't need a persistent storage. Edited August 24, 2016 by euc 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted August 24, 2016 Share Posted August 24, 2016 3 minutes ago, euc said: Technically, you just need a valid "voltage"/"percent" list for the euc you are riding. Then you could simply time how long it takes to drop by one percent and just calculate how far you could go at the same speed. The downside would obviously be that you have drive a few meters before an estimate can be calculated. But the upside is that you don't need a persistent storage. Right, as as noted, since you are using Arduino (have internal persistent memory) maybe is possible to use the last history values. But I wonder if such feature don't need much more work/investment to have a good quality for final users. 1 Quote Link to comment Share on other sites More sharing options...
esaj Posted August 24, 2016 Share Posted August 24, 2016 10 minutes ago, euc said: Technically, you just need a valid "voltage"/"percent" list for the euc you are riding. Then you could simply time how long it takes to drop by one percent and how far you got during that period. Then it's just a matter of extrapolating. The downside would obviously be that you have drive a few meters before an estimate can be calculated. But the upside is that you don't need a persistent storage. Just of the top of my head, something like this could maybe work: For the first few rides, measure the trip vs. watt-seconds (or something like that, fairly small time-range power usage) using the voltage & current reported by the wheel If the update interval is 200ms, you could take 5 last samples and calculate the average power (voltage * current) vs. trip Keep track of total trip vs. total watt seconds Store the data for different powers vs. travel to get a larger set of averages and the total watt seconds got out from the pack vs. trip Once the "calibration" rides are done, the software can (roughly) anticipate the remaining travel distance based on momentary power (kinda like how car computers estimate the remaining mileage for the remaining fuel using current consumption), probably should round it to nearest 1km or such, as the value can bounce up and down a lot (the power usage of the wheel is very spiky) 1 Quote Link to comment Share on other sites More sharing options...
euc Posted August 25, 2016 Author Share Posted August 25, 2016 (edited) My watches battery lasts for about 40-50 minutes with the screen being on and the Bluetooth being connected all the time. When I connect it, it draws about 40mA, when it is searching for the EUC it draws about 70mA. (@ 5V btw) On the battery it says 0.37Wh, but I'm only getting maybe half of that. I think the battery has not been charged/discharged properly. I'll definitely add another button to turn on/off the display. But the Bluetooth will still draw probably 90% of the power. I think I can get the HC-05 to use less power. From what I remember, there is a power saving mode that can be enabled. And I could also adjust the scanning interval and duration. All the parts for the watch combined cost about 8 US$ btw. HC-05, Arduino Pro Mini, 100mAh LiPo, I2C OLED display, Step up converter, Switch (To charge and protect the battery you might wanna add one of these Charging modules For me it was more like 6US$, as I have ordered all those parts in larger quantities btw. When the ESP-32 comes out it might even be a dollar cheaper. (In addition to being only a third the size. ) Edited August 25, 2016 by euc 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted August 25, 2016 Share Posted August 25, 2016 Maybe in future we an have this on the controller boards. As for real watches, I think Pebble have an API to access bluetooth devices and data - also Pebble is cheap and there is a lot of information about it, like ti uses a STM32F2xx Cortex M3. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.