After the various modifications, repairs and tests it was time to put the Furby back together. The speaker wires were soldered in place and all the cables hot glued to act as a basic strain relief. A hole was made through the battery box to route the wires through to the Edison (via the level shifters). The power cables were extended and a couple of damaged links on the board were replaced. Once that was done the case could be re-assembled.
Power
As mentioned previously the Edison needs 7v to be able to power the board and USB correctly. To support this a boost regulator was added to the circuit based on the popular XL6009 chip. I initially planned to keep the 5v regulator from the origional battery box but that was not working when I tried it. Instead, I added a switch so that the battery can be switched between charging and powering. This can also be used as an off switch. I used the 100Ω high power resistor from the LED downlighter to load the board whilst I adjusted the output to 7v. I also checked that it stayed at 7v when the load was off.
Level Shifters
I tested the level shifters with a dual power supply and a multimeter. Three worked as expected but one did not. Rather than 7v / 0v, there was around 2v on the output. So I swapped out the FRB590 with a BC549 and it tested ok.
H-Bridge
The H-Bridge has been wired up and tested with the Furby's motor.
Update 4/6
I nearly forgot to include the H-Bridge but luckily there was a bit of space under the Edison.
Edison
Thanks to gpolder and the pinout he found, soldering up the connections to the breakout board was straight forward.
Update 4/6
Perhaps not as simple as I first thought as when I checked it again today one of the pins was in the wrong place, VBat vs Pin19. So I resoldered those.
My MCU code needed to be updated to reflect the new pins selected. I believe I have these correct but need to test them.
gpio_setup(183, 0); /* set GPIO 183 DIG9 as input*/
gpio_register_interrupt(183, 1, IRQpulse);
gpio_setup(49, 0); /* set GPIO 49 DIG8 as input*/
gpio_register_interrupt(49, 1, IRQreset);
Software
For the software side, the Furby needs to respond the events happening on the car. By subscribing to the same message queue as the car we can use pretty much the same code as for the car but just have different actions.
The previously developed MCU app communicates to the motor controller via the host control API and a bidirectional (or duplex) stream.
The duplex stream has "on" events for when data is recieved and a write method to send data.
var stream = require('stream'); var util = require('util'); var fileduplex = require('file-duplex'); var mcu = new fileduplex('/dev/ttymcu0'); mcu.on('data', function(data) { console.log('Data %s',data); }); mcu.on('error', function(error) { console.log('Error %s', error); }); mcu.write("M"); //Request max value mcu.write("C"); //Request counter value //mcu.write("U"); //Count up //mcu.write("D"); //Count down
Putting that together with the MRAA code from previous, we get the motor controller class for the Furby.
var mraa = require('mraa'); var Motor = function (D1Pin, D2Pin, SpeedPin, HomePin, SensePin, mcuStream) { var self = this; self.MotorPin1 = new mraa.Gpio(D1Pin); self.MotorPin1.dir(mraa.DIR_OUT); self.MotorPin2 = new mraa.Gpio(D2Pin); self.MotorPin2.dir(mraa.DIR_OUT); self.MotorPinSpeed = new mraa.Pwm(SpeedPin); //PWM available on default swizzler positions. (3,5,6,9) self.MotorPinSpeed.period_us(700); self.MotorPinSpeed.enable(true); self.mcu = mcuStream; self.positionDelta = 10; //How many counter positions is close enough? self.counter = 0; self.max = 0; self.target = -1; //What counter position to goto self.mcu.write("M"); //Ask the MCU to get the maximum value self.mcu.on('data', function(data) { switch (data.substring(0,1)) { case "C": { self.counter = data.substring(1); if (self.InPosition()) { console.log("Position found at %d", self.counter); self.Stop(); self.target = -1; } setTimeout(function() {self.mcu.write("C") },10); break; } case "M": { self.max = data.substring(1); break; } default: console.log("Unexpected data recieved %s",data); } }); self.mcu.on('error', function(error) { console.log('Motor MCU error occurred %s', error); }); self.Reset = function() { //Set the motor running for long enough to trigger a reset then stop var timeForOneRev = 1000; self.Forward(); setTimeout(function() { self.Stop() },timeForOneRev); setTimeout(function() { self.mcu.write("C") },timeForOneRev); } self.Forward = function() { self.mcu.write("U"); self.MotorPin1.write(1); self.MotorPin2.write(0); } self.Reverse = function() { self.mcu.write("D"); self.MotorPin1.write(0); self.MotorPin2.write(1); } self.Stop = function() { self.target=-1; self.MotorPin1.write(0); self.MotorPin2.write(0); } self.Speed = function(percent) { self.MotorPinSpeed.write(percent); } self.Position = function() { return self.counter; } self.Max = function() { return self.max; } self.Distance = function(newPosition) { //What is the distance from the current position to the new position var p = self.Position(); var m = self.Max(); var D1 = newPosition - p; var D2 = (m - p) + newPosition; if (Math.abs(D1) < Math.abs(D2)) return D1; else return D2; } self.Direction = function(newPosition) { return Math.sign(self.Distance(newPosition)) } self.InPosition = function() { if (self.target == -1) return false; //Not going to a position return ((self.Distance() * self.Direction()) < self.positionDelta); } self.Goto = function(newPosition) { self.target = newPosition; if (self.InPosition()) { self.target=-1; return; } if (self.Direction(newPosition) > 0) { self.Forward(); } else { self.Reverse(); } } }; module.exports = Motor;
There's still a bit to be done with the software but I hope to have enough for a demo this weekend.
Reference
XL6009 DC-DC Converter Datasheet
https://nodejs.org/api/stream.html
https://www.npmjs.com/package/file-duplex
Previous Posts
Upcycle It Blogs tagged with upcycled_interactiveracecardriver
Top Comments