Monday, November 13, 2017

BLHeli as car ESC (brushless)


BLHeli as car ESC (brushless)

 Required parts and tools

- BLHeli Suite (description based on version 17.6.14.9.0.1)
  https://blhelisuite.wordpress.com/
- Flasher: Arduino UNO (a lot of other boards are supported by BLHeli Suite too)
- USB cable for Arduino UNO
- BLHeli ESC
- Six wires

Idea


Brushless ESCs for cars are usually quite expensive compared to airplane/quad ESCs, and  if you don't need a lot of power even the smallest ESCs are oversized.
Most airplane/quadcopter ESCs just know one direction, but with BLHeli there's a firmware that supports also bi-directional mode.

I used the cheapest I could find on aliexpress, '16A ESC for drone' in transparent shrink tube. They don't have a bootloader, therefor the first step is to flash them. I used a cheap Arduino UNO clone 'MEGA328P CH340G Arduino Compatible'.

Wiring

The ESC has six solder pads, and I prepared 6 needles glued together and wired to the Ardunio. The solder pads on the ESC are (from center to plus wire): MOSI, MISO, SCK, 5V, GND, RST. On the Ardunio  D10=RST, D11=MOSI, D12=MISO, D13=SCK, and GND=GND, 5V=5V. To actually program the ESC I removed a little bit of shrink tube above the pads, that I closed with hot glue after programming and writing the setup.

BLHELI flash pins, and mapping to Arduino UNO pin, as table and picture:
  • Atmel pin RST  <-> Arduino UNO pin 10
  • Atmel pin GND  <-> Arduino UNO pin GND
  • Atmel pin VCC  <-> Arduino UNO pin 5V
  • Atmel pin SCK  <-> Arduino UNO pin 13
  • Atmel pin MISO <-> Arduino UNO pin 12
  • Atmel pin MOSI <-> Arduino UNO pin 11
  

Flashing

The firmware for this specific ESC is SUNRISE_BLHELI_SLIM_30A, according to the seller, and this works also for the 16A ESCs. There are three versions available, I tried MULTI which can't be individually programmed, then MAIN which has no bi-directional mode and then TAIL which is the smallest of all versions.

I've used the following setup:

Low Voltage Limiter: 3.2 Volt/cell
Governor Mode: Off (voltage is proportional to TX, rpm is not (no rpm control by the ESC)
Startup Power: 1 (default)
Temperature Protection: On
Low RPM Power Protect: On
Brake on Stop: On
Motor Direction: Bi-Directinal
Demag Compenation: Off
PWM Frequency/Damped: Damped light
Enable PWM Input: Off (On a car keep it off, also to avoid signal errors)
Motor Timing: Medium (Unless your know the motor needs other settings keep the default)
Input Polarity: Positive
PPM Min Throttle: 1000 (change it from the default)
PPM Medium Throttle: 1500 (change it from the default)
PPM Max Throttle: 2000 (change it from the default)
Startup Beep Volume: 60 (low volume startup beep (motor vibration))
Beacon Volume: 200
Beacon Delay: Infinite (no beacon beep)



The drawback of this ESC is that you need to flash it every time you want to change the settings. There are other more expensive and bigger ESCs available with BLHELI that can be programmed using the one-wire protocol, they have more flash memory with the BLHELI bootloder. If you have one of these you can use the Arduino as one-wire adapter, and there's no need to flash the firmware to change settings.

Conclusion

A small and cheap brushless ESC for smaller cars is quite easy to make.




Saturday, November 11, 2017

3D printing - Sticky bed for FDM printers

Introduction

FDM printers usually come with a bed that isn't optimal in term of stickiness. And sometimes even the material isn't optimal or really flat.
Good materials:
- ceramic glass: Flat, hard and a very low thermal expansion coefficient of 0,1·10−6 1/K
- carbon sheets: Flat, hard and a very low, negative thermal expansion coefficient of -0,1·10−6 1/K
- epoxy sheets: Flat and hard
- glass sheets: Flat and hard
- pertinax/FR2 sheets: Flat

All sheets but pertinax can be just placed on the heated bed, there's no need to glue them or clamp them against the heated bed. I have 0.5mm carbon for smaller parts and 2mm carbon for larger parts, that are much larger than the heated bed and are only connected to a holder at the z carriage. Easy to swap and remove.

Pertinax has the advantage of good adhesion of PLA and ABS, and most likely also other materials, but it has the big disadvantage that it really likes to wrap, roll and bend. It must be properly fixed to the bed.

Make the bed sticky


There are a few options, sorted from worst to best:
1. Hairspray
2. Kapton tape
3. Blue tape
4. Jelly solution
5. PEI
6. Hairspray

  1. Hairspay: Most hairsprays don't help anything
  2. Kapton tape: It's hard to apply (straight, no bubbles) and is is not very sticky
  3. Blue tape: Easy to apply, can't stand higher temperatures. Use this if you don't have a heated bed.
  4.  Jelly solution: Jelly (or Jell-O) provides good adhesion, but it's lengthy to mix and apply. It must be reapplied quite often, it's not very long lasting.
  5. PEI: PEI (or Ultem, (polyetherimide)) provides very good adhesion, but there are a few drawbacks: PEI sheets are very bendable, even more the Pertinax, therefore it's impossible to just clamp them to the heated bed, and gluing without bubbles is virtually impossible. PEI coated build plates are good in theory, but it's possible to damage the coating (if the adhesion between the printed part and the PEI coating is higher than the adhesion between the PEI coating and the build plate), they are expensive and not available in every size.
  6. Hairspray: Some hairsprays have certain polymers, and they work like magic. Look for one of the following ingredients, it should be mentioned at the 2nd or 3rd position, maybe 4th but not later:
    •  acrylates/t-butylacrylamide copolymer
      • Tested: Garnier Fructis Stype EXTREME HARD
    • VA/Crotonates/Vinyl Neodecanoate Copolymer
      • Tested: Rave 4X Mega
      • Tested: Suave Extreme Hold

Hairspray selection

There a plenty of other hairsprays with these ingredients, no need to get exactly the ones mentioned above. Follow the links to get the lists:
http://www.cosmeticanalysis.com/cosmetic-ingredients/acrylates-t-butylacrylamide-copolymer.html 
http://www.cosmeticanalysis.com/cosmetic-ingredients/va-crotonates-vinyl-neodecanoate-copolymer.html

Hairspray application

The hairspray must be applied only once, and then the build plate shall be heated to bake the polymers onto the build plate. It'll be a slightly rough coating, and you'll have to scratch hard to remove it. You can print PLA, ABS, PETG, TPU/SoftPLA/igus/Nylon and most likely any other filaments on it. The printed parts pop off when the build plate cools down.
There's no need to reapply the hairspray (unless you damage the coating), and it can be cleaned even with soft cloth without destroying the coating.

If you don't have a suitable hairspray at home simply take your build plate to your hairdresser for a short extra treatment. Or just visit me.





Backup list (11.11.2017):
http://www.cosmeticanalysis.com/cosmetic-ingredients/acrylates-t-butylacrylamide-copolymer.html
Balea - Volume Effect Forming Water
Brigitte Lund - Volumen Trend Styler
Garnier - Fructis Style Gel-Spray Hard
Hair Haus - Haarspray Ultra Strong Hold
L'Oreal - Styling Spray
L'Oreal - Liquid Gel
L'Oreal Professionnel Paris  - Tecni Art - Air Fix 15 Haarspray
Loreal Paris - Studio Line Spurenlos Fx 8
Syoss - Haarspray Professional Performance
Today (Penny, REWE) - Haarspray Perfekter Halt
Trinity - Reload Finalizer Plus
Udo Walz - Volumen-Pflege
Wella - Wellaflex Sensitiv
Wella - Wellaflex Haarspray
Wella - Wellaflex Haarspray
Wella - Wellaflex Form & Finish Glanz-Haarlack
Wella - Wellaflex Glanz-Haarlack
Wellaflex - Farb-Brillanz Haarspray
Wellaflex - Wellaflex Form & Finish Glanz-Haarlack
Wellaflex Men - Mega Spray

http://www.cosmeticanalysis.com/cosmetic-ingredients/va-crotonates-vinyl-neodecanoate-copolymer.html
Alcina - Haarfestiger Extra Starker Halt
Aussie Volume Hairspray - Volume Hairspray
Aveda Be Curly Hairspray - Be Curly Hair Spray
Bigitte Lund - Ansatz Haarspray
Brigitte Lund - Volumen Haarspray
Dr. Baumann Cosmetic - Hair Spray
Dr. Baumann Cosmetic - Haarspray
Gard Professional Styling - Haarspray Normal
Gard Professional Styling - Haarspray Mit Bambusextrakt
Garnier - Haarspray Elastic Fixier-Power
Helen Of Troy Limited - Final Net
L'Oreal - Studio Fix & Style Fixier-Lack
L'Oreal Professionnel Paris - Infinium Lumiere
L'Oreal Studio Go Create - Fixation Ultra Forte
L'Oreal Studioline - Studio Fix & Style Fixier-Lack
Suave - Rave 4 X Mega Hairspray




OrangePi Lite and armbian - remove services you don't need

Linux Infra-red Remote Control

Uninstalling the service:
apt-get remove lirc

Stop the modules from being loaded at all:
echo install ir_lirc_codec /bin/true > /etc/modprobe.d/ir_lirc_codec.conf
echo install lirc_dev /bin/true > /etc/modprobe.d/lirc_dev.conf
echo install ir_mce_kbd_decoder /bin/true > /etc/modprobe.d/ir_mce_kbd_decoder.conf
echo install ir_sanyo_decoder /bin/true > /etc/modprobe.d/ir_sanyo_decoder.conf
echo install ir_sony_decoder /bin/true > /etc/modprobe.d/ir_sony_decoder.conf
echo install ir_jvc_decoder /bin/true > /etc/modprobe.d/ir_jvc_decoder.conf
echo install ir_rc6_decoder /bin/true > /etc/modprobe.d/ir_rc6_decoder.conf
echo install ir_rc5_decoder /bin/true > /etc/modprobe.d/ir_rc5_decoder.conf
echo install ir_nec_decoder /bin/true > /etc/modprobe.d/ir_nec_decoder.conf
echo install sunxi_cir /bin/true > /etc/modprobe.d/sunxi_cir.conf
echo install rc_core /bin/true > /etc/modprobe.d/rc_core.conf
echo install bmp085 /bin/true > /etc/modprobe.d/bmp085.conf
echo install pcf8591 /bin/true > /etc/modprobe.d/pcf8591.conf
The last two lines avoid the loading of modules for the BMP085 (barometric pressure, temperature and altitude sensor) and PCF8591 (8-bit A/D and D/A converter) that are not present on the Orange Pi Lite.

SFTP server

Remove "Subsystem sftp /usr/lib/openssh/sftp-server" from '/etc/ssh/sshd_config'

Remote syslog

Uninstalling the service:
apt-get remove rsyslog

Generally save energy

Go to '/boot' and edit the 'script.bin'. It can be converted to text and then edited. Convert it with
bin2fex script.bin script.fex
and back to binary with
fex2bin script.fex script.bin
E.g. disable all devices you don't need, e.g. disable the HDMI display and all output
('disp_init_enable = 0, mali_used = 0, g2d_used = 0').  You would do this only on a production system that won't ever have a screen attached, but not on your development system.

For details and other options:
http://linux-sunxi.org/Fex_Guide

OctoPrint video streaming

OctoPrint video streaming
Before you start to make sure your webcam supports MJPEG:
Install v4l-utils (apt-get install v4l-utils) and check the supported formats:
v4l2-ctl -d /dev/video0 --list-formats
There's usually at least one YUV format and hopefully MJPEG as well. The Microsoft Lifecam HD-3000 is - to my knowledge - the cheapest webcam supporting MJPEG at the moment (Q1/2017). The use of YUV will result in a high utilization of CPU and USB bandwidth at higher resolutions, therefore I would recommend to use these a webcam supporting MJPEG with OctoPrint (unless you're fine with 320x200 pixels using YUV).

Setup - short version
lsusb
apt-get update
apt-get upgrade
apt-get install libjpeg62-turbo-dev imagemagick libv4l-dev
ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
apt-get install subversion
cd ~
svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer
cd mjpg-streamer
make mjpg_streamer input_file.so input_uvc.so output_http.so
cp mjpg_streamer /usr/local/bin
cp output_http.so input_file.so input_uvc.so /usr/local/lib/
touch /etc/init.d/mjpg_streamer.sh
echo '#!/bin/sh
# /etc/init.d/mjpg_streamer.sh
# v0.2 phillips321.co.uk
# v0.3 Jenny Cash
### BEGIN INIT INFO
# Provides:          mjpg_streamer.sh
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpg_streamer for webcam
# Description:       Streams /dev/video0 to http://IP/?action=stream
### END INIT INFO

f_message(){
        echo "[+] $1"
}

# Carry out specific functions when asked to by the system
case "$1" in
        start)
                f_message "Starting mjpg_streamer"
                /usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -r 1280x720 -f 30" -o "/usr/local/lib/output_http.so"
                f_message "mjpg_streamer started"
                ;;
        stop)
                f_message "Stopping mjpg_streamer..."
                killall mjpg_streamer
                f_message "mjpg_streamer stopped"
                ;;
        restart)
                f_message "Restarting daemon: mjpg_streamer"
                killall mjpg_streamer
                /usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -r 1280x720 -f 30" -o "/usr/local/lib/output_http.so"
                sleep 2
                f_message "Restarted daemon: mjpg_streamer"
                ;;
        status)
                pid=`ps -A | grep mjpg_streamer | grep -v "grep" | grep -v mjpg_streamer. | awk '{print $1}' | head -n 1`
                if [ -n "$pid" ];
                then
                        f_message "mjpg_streamer is running with pid ${pid}"
                        f_message "mjpg_streamer was started with the following command line"
                        cat /proc/${pid}/cmdline ; echo ""
                else
                        f_message "Could not find mjpg_streamer running"
                fi
                ;;
        *)
                f_message "Usage: $0 {start|stop|status|restart}"
                exit 1
                ;;
esac
exit 0' > /etc/init.d/mjpg_streamer.sh
chmod 755 /etc/init.d/mjpg_streamer.sh
update-rc.d mjpg_streamer.sh defaults
#to remove it from default startup:
#update-rc.d -f mjpg_streamer.sh remove 

Source (setup - long version):
http://www.phillips321.co.uk/2012/11/05/raspberrypi-webcam-mjpg-stream-cctv/


Manual start of MJPG_Streamer
/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -r 1280x720 -f 30" -o "/usr/local/lib/output_http.so"
or
service mjpg_streamer start

service mjpg_streamer stop

service mjpg_streamer restart

Last steps
Reboot and verify that it is started automatically at startup.
Install ffmpeg
apt-get install libav-tools
apt-get install ffmpeg


and configure OctoPrint (Stream URL, snapshot URL, path to FFMPEG):
http://<ip>:8080/?action=stream

http://<ip>:8080/?action=snapshot
/usr/bin/ffmpeg

Stream URL (If your OctoPrint is at 192.168.0.5):
http://192.168.0.5:8080/?action=stream

Esprunio ESP8266 Wifi Setup

The Wifi parameters (SSID and password) can be configured programmatically, or they can be manually entered (using the IDE) and stored for later usage by programs. I'll describe the second option here, for usage as client with DHCP:
To manually configure Wifi execute the following command in the IDE (left side):
require("Wifi").connect("<ssid>", {password: "<password>"});
require("Wifi").getIP();
require("Wifi").getIP();
require("Wifi").getIP();

 

Replace <ssid> and <password> with your SSID and password. It'll take some time for the Wifi to connect, most likely you'll have to repepat the getIP command a few times (if you wait long enough only once, but if you're impatient even more than I did).

After you've got the IP address the configuration can be saved with the save command. This will save the SSID and password in clear text, and allows programs running on the ESP8266 to read this information with the command getDetails.

require("Wifi").save();
require("Wifi").getDetails();


To verify that everything works reset or restart (power cycle) the ESP8266, and recall the details with getDetails again.

reset();
require("Wifi").getDetails()
;
require("Wifi").getIP()
; 

In the ESPRUINO WEB IDE it'll automatically connect to the Wifi network.


To use Wifi in a program is now very simple, you don't have to hardcode SSID or password in your code but you can simply start a connection with the following code:

var wifi = require("Wifi");
wifi.connect(JSON.parse(require('Storage').read('.wificfg')).ssid,
{password: JSON.parse(require('Storage').read('.wificfg')).password}, function(err) { if (err) { console.log(err); } else { console.log(
wifi.getIP()); } });


That's it, almost.

To configure a fixed IP  address (e.g. when using an Android Hotspot as access point) and in cases where the Wifi access point doesn't allow to configure a fixed DHCP address you can set/change the IP address. Android Hotspot alway uses IP address 192.168.43.1 with the netmask 255.255.255.0. Use this code to change the IP address of the ESP8266 to 192.168.43.2:

require("Wifi").setIP(
  {
    ip:'192.168.43.2',
    gw:'192.168.43.1',
    netmask:'255.255.255.0'
  }, function(){}
);


That's it.