All Archive

Pinouts

Below you will find a diagram of the pin-outs of various controller boards I’ve pinched from the web. If you think there should be other board or component pin-outs post a note below and I’ll add it to the page.

Click on the images to enlarge.

Arduino

 

eps_logoESP/NodeMCU

 

raspberry_logoRaspberry Pi

flmobimooc – week 5

I have added sound to the game. You can see the method used here.

I have also added lives, and the ball speeds up when ever you score.

To add lives I first declare a variable mLives. I then set mLives to 3 in setupBeginning()

To show the remaining lives, I use a for loop in doDraw and place a red ball in the top left corner of the screen in a row, 20 pixels from the top and spaced 30 pixels apart (with an offset of 5 pixels from the left)

In game update, instead of losing the game, I remove one life every time you miss the ball. I then check if the number of lives is 0. If it is, I use the same old setState(GameThread.STATE_PAUSE); code.If we still have some lives left, I set the state of the game to Paused. I then place the ball in the centre of the screen and reset the speed to the same as the initial speed when the game starts.

To increase the ball speed is very easy.

When you check to see if the ball has hit the smiley face in the updateGame method, add the following code to increase the ball speed 5%.

//using the fraction between the original velocity and present velocity to calculate the needed
//speeds in X and Y to get the original velocity but with the new angle.
mBallSpeedX = mBallSpeedX * velocityOfBall / newVelocity;
mBallSpeedY = mBallSpeedY * velocityOfBall / newVelocity;

// Code added to speed up the ball.
// These are the only 2 lines required. Everything else is standard
// Speed up ball by 5% on every score
mBallSpeedX = mBallSpeedX * 1.05f;
mBallSpeedY = mBallSpeedY * 1.05f;

//Increase score
updateScore(1);

Take a look at my current TheGame.java file with all the updates so far. I have tried to add comments to explain what everything is doing.

Remember, if you want to add sound, follow the instructions on this page and download the file with the sounds from there, or add your own.

Files for week 5

These are the only files that differ from the originals supplied by Karsten. I have changed various parts for different features. Everthing should be commented. Right click to save the files or take a look at the Github Gists.

Please comment below if I have missed anything, or get it wrong.

Thanks.

The Huxley is here

Finally I have a working 3D printer.  It has taken a while and I’ve had a few problems along the way but I am now printing in 3D.

After a lot of time spent finding the parts and building a Reprap Prusa 3d Printer , I have failed to get it to print reliably.  After giving up in disgust at my inability to make it work I finally folded and brought a Raprap Huxley kit from Reprap Pro.

I have had some previous experience with the Prusa build and sailed though the construction.  It was also very easy to commission.  They have done a great job there of getting the kit together and getting the software set up for the printer.

Reprap Huxley

RoboBerry

I have started hacking at a robot controlled via a Raspberry Pi and an Arduino. I have a basic bot prototype working.

It consists of :-

  • Raspberry Pi running Raspbain Wheezy.
  • An Ardino Uno connected to the Pi via usb.
  • A motor driver shield for the Arduino.
  • A small robot base. This is an old Cybot base with 2 motors and a caster. This is all I am currently using from this robot.
  • A web cam.
  • A usb wifi adaptor.

Currently I have a small server app running on the pi that takes images from the web cam and this is streamed via http.

I have another small server written in python that displays a form with the image from the previous server plus some basic controls for the robot.

By clicking the buttons on the form I can control the motors on the robot base. I can see what the robot is seeing via the web can.

By forwarding the correct port on my router I am able to access this from anywhere via the web.

By using free dns service I am able to give my page a domain name and view the web page.

 

Arduino on the Pi

pi_logoplus ArduinoLogo

What a combination. High level Raspberry Pi gui with processing power and Arduino hardware smarts.

Now. How do we make it all work together.

I started with a Raspberry Pi model B 512

I brought an 8MHz 3.3v Arduino ATmega328 with boot loader Complete kit (Check the drop down menu under options) This is a diy clone of the Arduino Uno.

I built the kit on some prototype board. Very simple build.

(Pictures on the way)

The hardware connection from the RPi to the Arduino clone is simple.  Supply the clone with 5v to the Vin pin, 0v to one of the ground pins. Hook a wire up from the Arduino RX pin (D0) to RPi GPIO08 and Arduino TX pin(D1) to RPi GPIO10

Also connect a 0v line from the Rpi (GPIO6) to the Arduino clone Gnd connector.

That’s the hardware. Now for some software setup.

The linux distribution I’m using is the 2012-10-28-wheezy-raspbian available here.

You will need to be root to do most of this. You can either use the sudo command. eg. ‘sudo nano /boot/command.txt’ to edit the command.txt file, or you can become root by entering ‘sudo su’.

This will make you root until you enter exit or reboot the pi.

First. You will need to edit the /boot/command.txt

This is the unedited line from the standard installation.

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

We need to remove any serial port information and make it look like this :-

dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Edit the last line in /etc/init.tab. Add a # symbol in front of the last line

#TO:32:respawn:/sbin/getty -L ttyAMA0 115200 vt100

This will free up the serial port for our use.

Next , add the pi user to the dialout group.

usermod -a -G dialout

Last you need to add a link to the correct serial port because the Arduino environment does not recognise AMA0 as a serial port.

Create a new file

touch /etc/init.d/link_serial

Edit the file and enter the following text

#!/bin/bash

ln -s /dev/ttyAMA0 /dev/ttyS1

Save the file now.  Enter the following command to make the file executable.

CHMOD 755 /etc/init.d/link_serial

Now we need to make sure the file is executed every time the Pi boots.

update-rc.d link_serial defaults

You will get a warning

insserv: warning: script ‘link_serial’ missing LSB tags and overrides

This is not a problem.

To install the Arduino software environment enter the following command.

sudo apt-get install arduino

Reboot you Pi now.

You should now be able to program your Arduino clone via the serial GPIO pins on the Raspberry Pi.

You need to hold the reset button down until the program starts to download. Then release it as it starts. This takes a little practice…..

 

HDMI-vga cable hack

I brought an HDMI to vga cable from ebay.
This one in fact :- ebay hdmi-vga cable

To open the box I used a small scalpel to get between the two pieces of plastic in the middle of the join near the vga plug. I just eased the blade into the join and levered it apart. The cover is held on with a snap in connector along the edge of the pop out panel. Once the panel is off, just feed the HDMI cable into the strain relief rubber bung and the board should edge its way out of the box.

IMAG0275

IMAG0276IMAG0277

Its quite difficult to explain exactly how to get into this device but I hope the pictures give you and idea of what’s inside and how to approach it.

This cable is un-powered. It draws it’s power from the HDMI signal source, in this case the Raspberry Pi. This causes to much current draw though the diode on the board and will destroy  the diode over time.

To overcome this problem I opened the box and removed the power lead running from the HDMI plug to the board. I needed to carefully peel the hot melt glue off of the cable terminations and the board to access the solder pads.

DMIN_to_vga_hack

Then I added a fly lead to the 5 volt input for the board, and another to a ground point and bought these out thought a small hole in the case. I added a cable tie for a little strain relief.  Snip off the end of the old power lead to stop shorts inside the case.  Snap the front of the case back on and you are good to go.

IMAG0274

We now have a powered HDMI to vga cable adaptor. Fit the flying leads with a connector of your choice and connect to a 5 volt source. This could be a usb connector if you have a free socket on your hub or 0.1″ pin header if you are creating your own board or working with a bread board in your project.

Hope this is of use to somebody.

The Disclaimer – Upon opening the Product you have voided your warranty and the unit is now in your hands, no returns…

Secondly and even more important – you do the hacks/mods at your own risk, I am not responsible for damage to you, your equipment, or anything else within a 100 mile radius that may be directly or indirectly levelled, incinerated or otherwise obliterated to the ground (or neighbouring country) by your degree of skill (or lack of) with electronics, test equipment, soldering irons or hot coffee (not all necessarily used at the same time.)

Useless Machine……part three

< Useless Machine Part two

Code for the useless machine:  download source file

You can download the file above or you can copy and paste from the file below. (more…)

Useless Machine……part two

< Useless Machine Part one
Useless Machine Part three >

As it stands this is a very simple circuit with very simple code.

Useless Machine Schematic

Useless Machine Schematic

Click for a larger image

The complete circuit fits on a piece of strip board 10 strips X 14 holes.

Strip board circuit for useless machine

Strip board circuit

Most of the parts came from Rapid Electronics. They are local to me which is very handy.

I picked up a bunch of cheap servos on ebay with no connectors. Resistors etc came from my parts bin. I used a much larger voltage regulator than was needed as I had it on hand. I have substituted a better spec’ed part in the parts list. I also used a battery holder with a battery clip and fly lead with clip. I have spec’ed a simple battery holder with fly leads in the parts list.

Parts List
Description Order code Cost
ATtiny85 73-5122 £3.38
Relay 5v spdt 60-0787 £1.14
Da78l05 V Reg +5v 100ma To-92 47-3612 £0.26
Toggle Switch 75-0082 £0.655
Battery Holder 4xAA 18-3695 £1.21
2N22222 npn transistor 81-0256 £0.24
Capacitor 47 uf Elec 11-0815 £0.09
Capacitor 47nf Ceramic 08-1030 £0.136
IC socket 8 pin (tube of 60) 22-0107 £1.63
3 Pin Header 22-0500 £0.037
Resistor 2k2 Parts bin Pennies
Resistor 1K Parts bin Pennies
Hobby Servo Ebay Cheap

All the build details and picture to come in the next posts………

On to post 3. The source code……..

 

Useless machine

 Useless Machine Part two >

A simple toy using an attiny85, a servo and a toggle switch.

The idea is simple. A toggle switch is mounted on the top of a box. When turned on, a ‘finger’ pops out of the box, turns the switch off then returns to the box leaving the machine in a powered off state.

The finger will be attached to a servo horn.  When the switch is turned on, the micro will fire up, turn on a relay that by-passes the switch. It will then rotate the servo to move the finger to operate the toggle switch. The micro will then retract the finger and turn off the relay removing power to the circuit.

The micro I intend to use is the attiny85. Why ? Cause I had a couple to play with.

Why ? cause I had just go hold of the USBtinyISP byLadyAda from .:oomlout:. and…. err…

OK, So I have a new toy and wanted a simple project to use it for. This seems pretty simple.  Two outputs, the servo and the relay. No inputs. 5 Volt regulator and a power switch.

I grabbed an attiny85 and my trusty UsbTinyIsp programmer. Bread board awaiting, I add an led, power through a switch to the rails (5 volt regulated from the Bench psu).

Connect up a servo to one of the pwm pins (PB0 or PB1) and away we go…….

Ah.

My first problem is the code.

I can’t get a pwm generation going……..

Out with the scope.

Play with the code…

Recompile…

Reprogram chip…

Rerun program…

….and loop

After many iterations I get a working waveform.

Hook up the servo.

Trim the top and bottom values.

Wohooooo

Working servo control.

After getting the servo to move I had to trim the output.  The attiny can drive a servo beyond its home and full rotation positions.  To get the most out of the servo the code needs to be adjusted so it gets close to full rotation with out hitting the end stops.  This stops the motors and gearboxes in the servo being damaged.

To trim the servo you could use a variable resistor connected to an analogue input. Read this and adjust the servo until correct then output the value some where.  Instead of this I just tried a few values, entering each one in the code and recompiling. Start with a value below the max and approach it bit by bit. When the servo does not move any further for and increase in value, back the value off by one and use that.

I may add a trim feature to the circuit and software.  If this sounds useful, let me know.

On to part 2. The hardware.