Sunday, May 3, 2015

Primo - part 2

LEVEL: BOSS

We will presume that you read the original DIY instructions.

Instruction Box

Inside each command is a resistor. Putting a command in the Instruction box closes the circuit and based on the value of the resistor, the processor sends instructions to Cubetto. Simple and effective. Measuring the value of the resistor is done by means of a voltage divider: pair your unknown resistor with a known one and then measure how much of a voltage drop happens over each one. Basic math will give you answer.

In the DIY instructions, the brain of this console is Arduino MEGA. The reason is pretty simple: you need to probe 16 different resistors, and light up 16 LEDs. To sense 16 resistors you need 16 analog inputs and to light up 16 LEDs, you need 16 output pins. Arduino Uno board doesn't have that many pins, so the natural choice is the Arduino MEGA board that can handle all that.

Well, as most things in general, there is probably a different way to do it. We weren't happy with the kind of "brute force" method the instructions suggested. So, thinking for a while we came up with a more elegant solution. Main benefit is that instead of Arduino MEGA board, we could use Arduino Uno and just a few extra very cheap components.

Wiring

The main idea is to wire the 16 locations in a 4x4 grid. On one side, 4 digital pins will supply voltage, and on the other side, 4 analog pins will be used for voltage measurement.
Referring to the drawing: If you want to test the Resistance R10: set the Arduino pin D2 to high (all others to low) and read the value on the A3 analog pin.

It was necessary to put diodes (1N4148) in order to prevent leaking trough other resistors and messing up the circuit.

So, instead of 16 analog inputs (which Arduino Uno doesn't have), we reduced the problem to 4 digital sources and 4 analog inputs.

Resistors

Choice of resistors is very flexible. Since there are only 4 commands to distinguish, we can space them out in a way that reduces the chance of being detected wrongly. Below is a small Python script that does just that. In the beginning you can set 4 resistors used (probably what you have at hand) and it will give you out the voltages that Arduino will measure and also the power dissipated.

 __author__ = 'knitsandbits.net'  
 R=[330, 3300, 10000, 22000]     # selection of resistors available  
 V0=4.2                          # 5V - diode forward voltage (~0.8V)  
 R0=10000.0                      # reference resistance  
 for i in R:  
   print "resistor of " + str(i) + " Ohm:"  
   V1 = (R0*V0)/(R0+i)  
   power = V0**2/(R0+i)  
   print "voltage measured will be: " + str(V1) + " V, and power: " + str(power*1000.0) + " mW\n"  

Which gives you output:

 resistor of 330 Ohm:  
 voltage measured will be: 4.06582768635 V, and power: 1.70764762827 mW  
 resistor of 3300 Ohm:  
 voltage measured will be: 3.15789473684 V, and power: 1.32631578947 mW  
 resistor of 10000 Ohm:  
 voltage measured will be: 2.1 V, and power: 0.882 mW  
 resistor of 22000 Ohm:  
 voltage measured will be: 1.3125 V, and power: 0.55125 mW  

Obviously,  the voltages that will be measured are nicely spaced out. So this choice of resistors seems reasonable.

NOTE: In the Python script above, the voltages that are measured are actually voltages over the reference (10k) resistors. But this is the value that Arduino Uno will be measuring so it makes sense to calculate that one.

In the next part, we will explain how to wire 16 LEDs to Arduino Uno (that already has 8 pins occupied)
Part 3 (coming soon)

No comments:

Post a Comment