Hexbright, the (not so) open source flashlight

I recently got my own Hexbright and i’d like to share some considerations. This is not a full review, you can find some of them on YouTube if you want.

Open source

Let’s start from the title: open source? What? Really?

This flashlight was launched on Kickstarter and is very special. It has an Arduino-compatible microcontroller, which you can program to do whatever you want. Heck, it even has an accelerometer!While the description is not explicit, it should be clear enough that the goal was to made the source code available to the users so that they can customize it.
Also, the team wrote on Twitter that they were going to also open the hardware:

@jedibfa We are going to release mechanical drawings, electrical drawings, and source code for the Flex!! Thats what we mean by open source!

— HexBright (@hexbright) June 9, 2011

 

The project was funded on Jul 18, 2011 and the first units were shipped at the end of 2012 (as far i can tell).
As today another year is almost passed and a new revision of the Hexbright is being produced, the “V2″.

So, what’s the current status of the open source stuff?

Software

The software is available at GitHub and is complete. There is the factory-installed firmware, some examples and the bootloader:
https://github.com/hexbright
The source code is missing a license, something some people is complaining about. I’m not a lawyer but apparently, in many parts of the world, if you don’t specify a license then the writer keeps the copyright on that code. So it’s probably still not Open Source in the way we are used to.

Electronics

The first version of the Hexbright was shipped with the electronics V0.7 and the Hexbright V2 is shipped with a pcb marked as V0.8.
The schematics were available in the now dismissed wiki, and the last version is V0.5, which is a pre-production version:
http://www.crowdthunder.net/hexbright/elec/hexbright-flex_v0_5_schematic.pdf
On the main website they have published a partial schematic of the production Hexbright, which does not include the led driver, power supply and battery charging:
http://cdn.shopify.com/s/files/1/0180/3005/files/HexBright-Schematic-Pic.JPG
This partial schematic and the “property of Hexbright” text in the corner looks like that have changed their mind about making it Open.

Mechanics

This is not my field but i think there is some very incomplete data here:
http://community.hexbright.com/c/Bodies

Conclusion

I think that we are halfway between closed and open source/hardware. I think that Hexbright is not really liable because it didn’t specify a license for the source code on Kickstarter and the hardware promises made on Twitter are not part of the project as it was proposed. Anyway, i can’t say that i’m really satisfied of how things are going. Questions about Open aspects of the project remain unanswered on the Kickstarter page.

Personal considerations on the product

Ok, let’s talk about the product.

The flashlight feels very solid and gives a good feeling when you keep it in your hand. The materials are certainly of good quality.
The button makes a good click and the size is just ok.
The light is strong but i would not call it powerful. It’s the right light you would expect from a flashlight of this size. It’s better than other flashlights i have in the house though.

There is a little thing that i’d like to talk about because it’s a weak point of this device.
The microcontroller is configured to use an external Crystal to run its oscillator. This crystal can break if you drop the flashlight.
If this happens, you have successfully bricked your new toy. This is a real problem, in fact some users have already broken their Hexbright this way. The Hexbright V2 uses a different kind of crystal but it broke too in my flashlight after a drop.
If you have the tools i’d recommend you my easy fix: reprogram the fuses of the AVR microcontroller to use the internal calibrated RC oscillator. It has the same frequency of the crystal and even if it’s less precise you shouldn’t have issues to communicate with the serial port. The oscillator is calibrated at 25°C (room temperature), you just need not to reprogram the flashlight when overheated or when you are at the north pole :D

Got questions?

Feel free to ask me some questions in the comments if you want to know something in particular.

SPI over GPIO in OpenWrt

The previous posts Controlling leds status in OpenWrt and Controlling GPIOs in OpenWrt were actually an introduction for this.

Introduction

What if you want to connect some kind of SPI device to your OpenWrt device? Perhaps a microcontroller (AVR/Arduino, PIC, etc).
I recently worked on a project where i needed to have a web user interface and control an IR led emitter to emulate a remote. I considered that using an Arduino + Ethernet shield + some kind of flash storage + power supply + container box would cost me more than a TP-LINK MR3020 plus a bunch of components.

It turns out that the Linux kernel already has some modules to bitbang an SPI over the GPIO pins (spi-gpio + spi-bitbang) and also a module to expose the SPI to userland so that it can be accessed by our programs or scripts (spi-dev).
BUT there’s a problem. This stuff is not “directly” usable: it is used by other kernel drivers. We don’t have a way to dynamically say “hey, i want an SPI on those pins”. Instead we would need to rebuild the kernel adding some custom code to declare this SPI bus and also devices connected to it.
I don’t like the idea to recompile the kernel for something like this. I probably want to use this small linux box for tests, POCs, different projects, and i don’t want to rebuild the kernel and flash a new image each time.
So, i made a kernel module that allows to configure on-the-fly an SPI bus and its nodes. You can use it on a stock Attitude Adjustment image, without reflashing or recompiling anything.

By the way, if you wonder how fast this SPI can be, my tests show that it can go something above 1 MHz. Not bad at all.

Installation

I have submitted a patch to the OpenWrt developers. They may add it to the next release (not sure honestly) and be installable with opkg. But in the meantime i have built the module for the various platforms on Attitude Adjustment and you can install it manually.

  1. Click here to download the kernel module.
  2. Copy the file spi-gpio-custom.ko for your platform in /lib/modules/<kernel version>/  (TP-Link is ar71xx – for other boards it’s the same of the image you have downloaded)
  3. Run opkg install kmod-spi-gpio
  4. Run opkg install kmod-spi-dev

UPDATE
the patch has been included in OpenWrt trunk, so it is now available in nightly builds and will be in future releases starting from Barrier Breaker.
The installation is straightforward:
#opkg install kmod-spi-gpio-custom

Usage

You can use the module to configure up to 4 buses with up to 8 devices each, according to the parameters that you use when loading the module.

The command you’ll use is:
#insmod spi-gpio-custom <parameters>

Here is the official doc from the source:

 *  The following parameters are adjustable:
 *
 *    bus0    These four arguments can be arrays of
 *    bus1    unsigned integers as follows:
 *    bus2
 *    bus3    <id>,<sck>,<mosi>,<miso>,<mode1>,<maxfreq1>,<cs1>,...   
 *
 *  where:
 *
 *  <id>       ID to used as device_id for the corresponding bus (required)
 *  <sck>      GPIO pin ID to be used for bus SCK (required)
 *  <mosi>     GPIO pin ID to be used for bus MOSI (required*)
 *  <miso>     GPIO pin ID to be used for bus MISO (required*)
 *  <modeX>    Mode configuration for slave X in the bus (required)
 *             (see /include/linux/spi/spi.h) 
 *  <maxfreqX> Maximum clock frequency in Hz for slave X in the bus (required)
 *  <csX>      GPIO pin ID to be used for slave X CS (required**)
 *
 *    Notes:
 *    *        If a signal is not used (for example there is no MISO) you need
 *             to set the GPIO pin ID for that signal to an invalid value.
 *    **       If you only have 1 slave in the bus with no CS, you can omit the
 *             <cs1> param or set it to an invalid GPIO id to disable it. When
 *             you have 2 or more slaves, they must all have a valid CS.

Your platform will have GPIOs numbered in a certain range, for example 0-50 or 400-900 (see the OpenWrt Wiki for your router). Anything outside that range is an “invalid value” per the notes above.

For each device a file on /dev will created, named spidev<bus id>.<dev id>. For example, /dev/spidev1.0

Admittedly, it’s not easy to remember. But reading that reference when you want to change something is still less annoying than rebuilding and reflashing everything, right?

Examples

We all know, examples make everything so much easier to understand. (examples are for a TP-Link MR3020)

Single bus with id 1, using gpio 7 as CLK, 29 as MOSI, no MISO and single device in spi mode 0, max 1Khz, with no CS:
#insmod spi-gpio-custom bus0=1,7,29,100,0,1000
This will result in:
/dev/spidev1.0

Single bus with id 1, using gpio 7 as CLK, 29 as MOSI, 26 as MISO, first device in spi mode 0, max 1Khz, with gpio 0 as CS, second device in spi mode 2, max 125Khz, with gpio 17 as CS:
#insmod spi-gpio-custom bus0=1,7,29,26,0,1000,0,2,125000,17
This will result in:
/dev/spidev1.0 and /dev/spidev1.1

Bus with id 1, using gpio 7 as CLK, 29 as MOSI, no MISO, with single device in spi mode 0, max 1Khz, with no CS and Bus with id 2 using gpio 26 as CLK, 17 as MOSI, no MISO with single device in spi mode 2, max 125Khz, with no CS:
#insmod spi-gpio-custom bus0=1,7,29,100,0,1000 bus1=2,26,17,100,2,125000
This will result in:
/dev/spidev1.0 and /dev/spidev2.0

Transferring data

Ok, now how do we transfer data?

Simplex communication is done by just writing and reading that /dev file.
For example,
#echo hello > /dev/spidev1.0
will send “hello\n”, where \n (LF) is added by echo.

For full duplex data transfer you need to use ioctl calls. See the spi-dev documentation. You can also see an example here.

Troubleshooting

If something fails, insmod will give you a description of the fault code, which is very generic and will usually tell you nothing about what happened.
To understand what’s wrong, see the kernel log running dmesg.

If you want to change your configuration, you need to unload the module and reload it with different parameters:
#rmmod spi-gpio-custom
#insmod spi-gpio-custom <new parameters>

Last, but not least, remember to unload other modules that may keep the gpio busy, for example leds_gpio:
#rmmod leds_gpio

Reference

<linux source>/Documentation/gpio.txt
<linux source>/Documentation/spi/spi-summary
<linux source>/Documentation/spi/spidev

Controlling GPIOs in OpenWrt

This is a small guide to control GPIOs on OpenWrt.

First of all, you may need to unload other modules that could be using the GPIOs you want. In particular, if you want to use a GPIO which is connected to a led you’ll probably need to unload leds_gpio:
# rmmod leds_gpio

Every GPIO will have an entry in /sys/class/gpio. If you don’t see the GPIO that you want to use then it has not been configured yet. You do so by writing the GPIO number in the export file, for example:
# echo 26 > export
Then a directory for that gpio will appear, in my case gpio26. In this directory we find the files we need to control this gpio.
You want to write out to the direction file to use it as an output, or in to use it as an input:
# echo out > direction
# echo in > direction

The value file is used to – you guessed it – set or get the status of the GPIO:
# echo 0 > value
# echo 1 > value
# cat value

The active_low file is similarly used to negate the value when it’s… well, active low!

Reference: <linux source>/Documentation/gpio.txt

Controlling leds status in OpenWrt

This is a quick how-to about controlling the status of the leds from userspace in OpenWrt.

If you have installed OpenWrt on your router the leds should be controlled by the leds_gpio kernel module. Every led will have an entry in sysfs under /sys/class/leds

To manually control a led you should first set the trigger file to none, otherwise the led will be controlled for its original function, i.e. ethernet activity indicator:
echo none > trigger
Then you can set the value by writing to the brightness file. This file represents the brightness level which should range from 0 to the value contained in the max_brightness file. However, in most cases there will not be hardware brightness control for the leds (like with GPIO), so 0 will turn OFF the led and any non-zero value will turn it ON:
echo 0 > brightness
echo 1 > brightness

An example on my TP-Link MR3020:
root@OpenWrt:~# cd /sys/class/leds/tp-link\:green\:3g/
root@OpenWrt:/sys/devices/platform/leds-gpio/leds/tp-link:green:3g# echo none > trigger
root@OpenWrt:/sys/devices/platform/leds-gpio/leds/tp-link:green:3g# echo 1 > brightness
root@OpenWrt:/sys/devices/platform/leds-gpio/leds/tp-link:green:3g# echo 0 > brightness

Note: if you don’t already know, those files are not actual files in flash, they’re virtual files that act as an interface from userland to kernel.
Note 2: if you want more control on the GPIO lines you may prefer to unload the leds_gpio module (with #rmmod leds_gpio) and directly control the GPIO and/or configure a bus on some lines, like i2c or spi.

Reference: <linux source>/Documentation/leds/leds-class.txt

How to fix the Windows clock with BootCamp 5

I own a Macbook since i occasionally want to mess up with iOS stuff and i think it’s a great piace of hardware, but as a main OS i still use Windows.I have used Windows 7 and 8 with BootCamp 4, then i discovered that Apple eventually released BootCamp 5 and decided to do the update. After that i discovered that my clock was always wrong, 2 hours off the real time in my case. If you’re reading this, you probably have this same problem right?

So, why this happens and how to fix it?
I didn’t spend too much time on it, however it seems that Linux and OS X store the time as UTC in the hardware clock, while Windows stores it in local time (like UTC+1 and daylight offset). BootCamp sets a key in the Windows registry that should tell Windows to store it in UTC too, but apparently something doesn’t work correctly.

After some test i was able to fix it by letting Windows store the time as local time in the hardware, like it is designed to do. The registry key dosn’t seem to be documented so it’s probably not very reliable. This should mean i’ll get the wrong time on OS X but i don’t care since i never use it.

TL;DR
This will fix the clock in Windows and will probably get it wrong in OS X

  1. Launch regedit: [Win]+R, type “regedit” and press Enter
  2. Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
  3. Double click the “RealTimeIsUniversal” key and change the value from 1 to 0.
  4. Close regedit
  5. Reboot (i think it’s important to do a reboot, not power off and power on as in Windows 8 power off should work like an hibernation if i remember correctly)
  6. Set the clock to the right time

ASUS ET2220INTI-B014K

Sometimes i think manufacturers do not want to sell their stuff. I go to their website and in the products section i see very few info about them. Apart some general data like the screen size, processor, ram and alike.

I was searching an all-in-one PC for a project and ended up buying the ASUS ET2220INTI-B014K and despite the time i spent on the web i still wasn’t sure what i would find in the box. So i’m going to tell you something you won’t find anywhere else.

What’s in the box?

  • the PC itself (no kidding) WITH the TV tuner connector
  • the power supply (IN: 100-240V/50-60Hz OUT: 19VDC 6.84A)
  • a wireless keyboard
  • a wireless mouse
  • the USB wireless adapter for keyboard and mouse
  • a remote (uh? this wasn’t expected at all)
  • the 4 screws to mount the PC to a VESA support

I had no idea which accessories were included so you may wonder the same.

Some considerations

The PC looks fine and performs as expected, nothing wrong to note.

The noise is quite low, a bit louder than my MacBook, but certainly not annoying.

The remote is not that great, the power button can sleep and wake the PC but the rest of the buttons are mostly not working outside the application used to watch the TV (which, by the way, runs in Desktop mode, not Metro).

The monitor brightness can NOT be adjusted from Windows (Charm bar > Settings), you can set it via the OSD. But, the monitor supports DDC/CI so you can also set it using ScreenBright

There are some utilities that actually do no suck! Amazing! An utility shows the current power consumption in Watts, in realtime, and allows to set a green mode that uses a bit less power (not investigated what it does). The showed idle power consumption is 34W with minimum brightness and 41W with maximum brightness. Didn’t test other conditions so far. Another utility allows to update the bios, the boot logo and also allows to enable some kind of USB fast-charging mode that apparently allows to get more current from the USB ports so you can charge your mobile devices “3 times faster”. The iPhone/iPod/iPad devices are explicitly mentioned as supported.

Finally opened my blog

So, after failing to open by blog on Blogger (being detected as spam) i decided to give WordPress.com a try, so far so good.

I’m going to post here some random info that i think may be useful to someone else on this planet. I often end up finding the answer to my questions on other people’s blog so i decided to try to give my contribution too.

Follow

Get every new post delivered to your Inbox.