So that I could tell if the car had bumped into anything I wanted to put some microswitches into the bumpers. I had recently stripped down a paper shredder and had stripped out a few useful parts including a couple of micro-switches. Luckily these were the same size as a couple of others I already had (which may have come from my previous shredder).
As mentioned in the discussions I was concerned over the number of I/O used by the car and wondered if it was possible to connect all of the switches on one input. I'd previously seen the idea of using a resistor ladder into an analogue input. However, I wondered if that could be adapted to support multiple buttons. I came up with a schema using the change over connections of the micro switches before realising that I did not have these connections on my two new switches. However, I also realised that I could use a couple of ports, one for the front and one the back. Unfortunately, this means I don't have ISRs on the bumper switches but that can be handled in the software instead.
I put the circuit in the simulator again so I could rapidly play with resistor values. I came up with the ratio of R1 = R2, R3 = 2 x R2 which gave the values of 5v, 3.3v, 2.5v and 2.0v for the different switch settings. I had originally used push buttons but then realised I could not press 2 at once in the simulator. Of course, you could also do this with simple maths too. BBC - Higher Bitesize Physics - Resistors in circuits : Revision
Software for sensors
I did look into using the MCU to monitor the switches but the ADC is handled by the Arduino breakout and the MCU does not handle floating point. So I'm not saying that it's impossible but it is undocumented and there are numerous challenges to resolve.
So I stuck with using MRAA and Node for the Analogue inputs. The code in the "setInterval" function polls the analogue input every 100ms. If it has changed from one of the 4 states then it raises an event which is picked up by the "listener" function, this simply writes the data to the console but in the real car it would cause the car to stop and the driver to say something like "ouch".
var mraa = require('mraa'); var events = require('events'); var listner1 = function listner1(value) { console.log('Bumper:%d' , value); } var eventEmitter = new events.EventEmitter(); eventEmitter.addListener('bumper', listner1); var previous = -1; var analogPin0 = new mraa.Aio(0); //setup access analog input pin 0 //Monitor the bumper analogue pin and raise events if it changes setInterval(function () { var analogValueFloat = analogPin0.readFloat(); var newval = floatToSwitch(analogValueFloat) if (newval != previous) { eventEmitter.emit('bumper',newval); previous = newval; } } , 100); var BumpEnum = { None: 0, Left: 1, Right: 2, Both: 3 }; //Scale the input to one of our 4 values depending on //which of the two switches are pressed function floatToSwitch(value) { if (value < 0.45) return BumpEnum.Both; if (value < 0.58) return BumpEnum.Left; if (value < 0.83) return BumpEnum.Right; if (value >= 0.83) return BumpEnum.None; } process.on('SIGINT', function () { console.log("Shutting down SIGINT (Ctrl-C)"); process.exit(); });
Pins and cables
I came up with the following wiring that allows me to use the grove connections without modification and not need to create any clever split cables to handle front and back.
Lights
- Brake lights - Pin 1
- Headlights - Pin 5 (PWM)
- Indicator L - Pin 3
- Indicator R - Pin 4
Motor
- Motor Speed - Pin 6 (PWM)
- Motor 1 Direction - Pin 7,8
- Motor 2 Direction - Pin A3, A4
From: https://github.com/intel-iot-devkit/mraa/blob/master/docs/edison.md - AIO pins are treated as 0-5 in mraa_aio_init()
but as 14-19 for everything else.
Therefore use mraa_gpio_init(14)
to use A0 as a GPIO
Bumpers
- Bumpers A0 and A1 (split front and back), resistor ladder to be used to allow left and right switches to be independently detected.
Light Sensor
- Light sensor - A2
Cables (10 needed)
- Front Lights - D2, D4
- Rear Lights - D3, UART
- Motor - D6, D7, A3
- Bumpers - A1
- Ambient light sensor - A2
So that's pretty much all that can be added so if I need anything else it will have to break out via I2C and need to buy some more cables
Assembly
I've started soldering up some of the sub-modules that make up the car.
The main drive motors have been fitted with new wires that came from an old PC power supply, the motor drive board has been started and the headlights / indicators have been soldered up. As there are quite so many LEDs for the headlights, I'll use a simple transistor switch to boost the current to those and for the brake lights too.
Reference
tronixstuff.com/2011/01/11/tutorial-using-analog-input-for-multiple-buttons
https://github.com/intel-iot-devkit/mraa/blob/master/examples/javascript/AioA0.js
https://github.com/intel-iot-devkit/mraa/blob/master/docs/edison.md
Previous Posts
[Upcycle It] Interactive Race Car Driver - Plan of action
[Upcycle It] Interactive Race Car Driver - Software
[Upcycle It] Interactive Race Car Driver - Lights
[Upcycle It] Interactive Race Car Driver - Detailed Plan
[Upcycle It] Interactive Race Car Driver - Edison
[Upcycle It] Interactive Race Car Driver - Drive Motor Testing
[Upcycle It] Interactive Race Car Driver - Car modification
Top Comments