Simplifying the MCP23017 - written by NiXijav on 2016-03-01
Library for the Raspberry Pi written in Python that simplifies the use of the MCP23017, a 16 bit GPIO expander
The MCP23017 is a very useful IC. It provides 16 GPIOs, and it's ideal for expanding the ports of a Raspberry Pi. It even includes pullup resistors for each pin, and all of this using i2c.
You can find the datasheet for this chip here
But all this benefits come at a price. It is not easy to use, or at least, not easy to use initially. The MCP23017 operates entirely based on registers (Page 9 of the datasheet), and depending on which register you are writing to, you'll be able to change the direction of the pins, state, pullups... Also, GPIOs are divided into two different banks, and they are independent from each other.
To simplify this boring register thing, I created a library, in Python, for the Raspberry Pi. Commands are almost the same as the RPi.GPIO ones.
Here is the pinout the library uses:
A very simple code example:```
import mcp23017_lib as MCP
MCP.setup(2, MCP.IN, MCP.PUHIGH)
This example will set pin #2 as an input, with the pullup resistor enabled and #1 as an output. When the input goes high, pin #1 will also go high.
You can find the library here. It is licensed under the GPLv3.
If you found this library useful, and/or have suggestions, please let me know in a comment :3
Upgrading a mouse with a 555 timer - written by NiXijav on 2015-12-20
Cookie Clicker is fun, but it is necessary to click a lot so my finger gets tired and my mouse broken. So, why not use a 555 timer to automate clicks?
I've been playing Cookie Clicker for the past hour. It is very addicting, but it advances quite slow. It is also necessary to click a lot, so mi finger gets tired and my mouse, destroyed. So, why not use a simple 555 timer to perform automatic clicks? Let's go!
The 555 timer is one of the most sold and used ICs in the world, due to its low cost, ease of use and application diversity, that ranges from a delayed switch to an oscilloscope. Here's a datasheet for the chip.
The timer has several working modes, monostable, bistable and astable. The one we need is the astable one.
In this mode, the chip will provide a constant pulse sequence specified by us. This is what we want to achieve, fast and constant pulses, just as if we were clicking the mouse.
Here's the circuit:
Quickly making this circuit on a breadboard, and connecting the output to an LED (instead of the mouse) we get this:
What frequency is being achieved with this circuit?
Wow! 18.5 Hz! Quite impressive, isn't it? That's a huge improvement over the manual click. Oh, and don't forget the period:
Furthermore, we can calculate charge and discharge times:
After all this calculations, and checking that the circuit is working properly, let's solder everything. In short, you must first check that there is room inside the mouse to house the circuit. It will be powered by the USB bus power itself. The following photos describe this process:
This mouse is very easy to open. Just 4 screws on the base and the top just pops off.
Next, remove the board from the case and analyze where cables should be soldered (V+, V- and signal).
V+ and V- come directly from the USB, and the signal wire should be soldered to the push button contact. This way, the button will preserve its original behaviour, but when we press the new added button, the signal will be sent through the original, performing the clicks. After connecting everything, we proceed to the reassembly.
Be careful when accommodating the cables! Oh, and, my finger is pointing to the new button. After everything is again in place, my mouse looks like this:
And last, but not least, quick check on cookie.riimu.net/speed
Nixie bargraph clock - written by NiXijav on 2015-11-18
What happens when you combine an Arduino with something more vintage? Yes, a Nixie bargraph clock.
Recently I bought a couple of IN-9 Nixie bargraph tubes from a russian store, $1.5 each (quite cheap, huh?). These tubes are current driven, and they are fairly constant between 0 and 8 mA (Almost the end of the tube). Above that, sensitivity decreases rapidly. So, after keeping them in a shelve for some days because of not having any idea on what to do with them, I decided to make a clock.
A clock? - you might ask. Yeah, a clock. Neither analog nor digital. (Well, it is analog, but you know what I mean) Just the tubes displaying the time.
So, what do we need?
Obviously we're going to need the tubes and an Arduino (I'll be using a Pro Mini). Also, as the tubes run at 140v, an appropiate PSU is required. Mine boosts voltage from 8~32V to 100~390V, and it only costed ~$10. Also, I got a very nice wooden enclosure in a local store for just $3.
How to drive the tubes
The main problem about driving each individual tube is the voltage itself. The Arduino is a 5 volt device, and 140v would very likely release the magic smoke. To avoid this, a high voltage transistor, like the MJE340, will be used. The first problem is now solved.
Another problem is the lack of a true analog output of the Arduino. Instead, it uses a PWM signal. The easiest solution is using a low pass filter, so the output PWM will be smoothed, much like an analog signal.
Take a look at the schematic of one of the tubes:
<irony>Now admire the internal magnificence of the clock!</irony>
Quick description of each part
- Low pass filters and transistors for each tube
- 140V Power supply
- Arduino Mega (Right now I'm using a Pro mini)
- Tube connections
- Decorative voltmeter
One of the problems of the tubes is that each one is unique, so under the same voltage and current, two tubes can have slightly different heights. To adjust this, the resistor located on the emitter of each transistor should have the appropriate value. You could also put a potentiometer for easier adjustment.
The final result!
So, how does this... strange clock look like? Here, take a look!
And there you have it! A steampunk vintage clock!