Showing posts with label picaxe. Show all posts
Showing posts with label picaxe. Show all posts

Thursday, May 01, 2008

Let's Sync Nanoloop to Prophet 64

Demo video: http://youtube.com/watch?v=rSsOCTmW8pQ


About
This little project lets you control the speed of Nanoloop 1.3 (might work with other versions also) via the Prophet 64 program for the Commodore 64 computer. It works on the basis of converting a Sync 24 signal to a Nanoloop clock signal. It will react to start/stop signals (Commodore Userport pin E --> 08M leg 4) and a sync 24 clock pulse signal (Commodore Userport pin F --> 08M leg 6).

The IC that is used is the inexpensive Picaxe 08M, which can be programmed with an easy-to-make serial download cable and a free software program editor. If you like, I can flash a Picaxe 08M for you, so please feel free to contact me regarding this.

I have not been able to get a hold of the Commodore 64 Userport 24-12 edge connectors at a reasonable price. Instead, I have simply hacked apart a 44-22 edge connector which costs about AU$2.50. A very cheap solution, and it works fine.

Breadboard prototype.

Hardwired version in action.

Using the Interface
1. Make sure everything is turned off. Plug in the Userport connector to the Commodore 64. Plug in the Game Boy link cable connector into the Game Boy.

2. Load up or make some Nanoloop loops. Set Nanoloop to external sync, by going to the tempo indicator and pressing A and B (this in 1.3b, not sure about other versions).

3. Load up the Prophet 64 program on the Commodore. Load or make a song.

4. When you press play or stop on the Commodore, the Game Boy will follow. When you change the tempo on the Commodore, the Game Boy will follow.

Please note that although the Commodore 64 will go back to the beginning of a bar (when using the Sequencer) after pressing stop and then play, Nanoloop will not automatically always start from the start of a bar. So it is a matter of practice to get the sync correct.


Schematic (including Picaxe download circuit, for a blank 08M chip):


Schematic (for a pre-programmed 08M chip):
I am not sure if the 12kΩ resistor is strictly required. You might get away with not including it. But for the extra four cents, just put it in.


Power Source:
The circuit requires a 5V power source. I don't think that the Commodore 64 User Port has a 5V source on it, but I could be completely wrong about this (-- can anyone confirm or deny?). A suitable supply voltage can be obtained from a number of places:
• The joystick ports on the Commodore 64.
• A USB port on a PC or laptop.
• Three AA batteries (1.5V x 3 = 4.5V).
• Four AA rechargeable batteries (1.2V x 4 = 4.8V).
• A 9V battery with a 7805 regulator.
• A 9 to 12V AC/DC mains adaptor with a 7805 regulator.
• The VCC pin of a six wire sync cable for a DMG-01 Game Boy. I am unsure if a Game Boy Colour will be able to supply 5V on this line (-- can anyone confirm or deny?). Thanks for the reminder, Matt.

It really depends on your personal preference which is the most suitable for your setup.


Picaxe Code:
symbol flag = b0
symbol flipflop = b1

main:
if pin1 = 1 and pin3 = 1 and flag = 0 then go_flip
if pin1 = 0 then reset_flag
goto main

go_flip:
if flipflop = 0 then go_high
if flipflop = 1 then go_low

go_high:
high 2
flipflop = 1
flag = 1
goto main

go_low:
low 2
flipflop = 0
flag = 1
goto main

reset_flag:
flag = 0
goto main

Wednesday, February 13, 2008

Reading a PS/2 keyboard using Arduino and Picaxe

So, i have a Picaxe 18X just lying around, not doing much at the moment. So i thought, why not put it to good use?

This involves reading key presses on a standard PS/2 keyboard using the KEYIN command from the Picaxe and then sending the key data to the Arduino. It is all very straightforward, and of course the strain on the Arduino is very minimal (compared to actually trying to code and read the keyboard purely in Arduino).

The good news is that it only uses a few resistors as external electrical components.

This is the exact schematic that i used, and it works great. Please note that this does not include the download cable for the Picaxe - refer to the first Picaxe user manual for more details. In reference to the pinheader - Arduino pin 1 is 5V, pin 2 is the RX pin and pin 3 is ground. The PS/2 pinheader is numbered as a standard mini 6-pin DIN connector.

Picaxe Code:
main:
keyin
serout 7,N2400(keyvalue)
goto main


Very quick and dirty Arduino code -- at least it sees something!
byte data;
byte old = 0;

void setup() {
Serial.begin(2400);
}

void loop() {
if(Serial.available() > 0) {
data = Serial.read();
if(data != old) {
Serial.print(data, DEC);
old = data;
}

}
}

Thursday, July 19, 2007

SPI using picaxe


Tonight is the first time that i have successfully used the SPI protocol with a Picaxe chip (not on a 28X1 or a 40X1 that have it as part of their software library). To be honest, i hadn't tried before today - just didn't get around to it. But this is really a useful thing. In the example code below, i controlled the resistance of one of the pots on an MCP42100 IC.

The picture above shows outputs 0, 1 and 2 of the Picaxe 08-M being used as the CS (chip select), SCK (spi clock) and MOSI (master out, slave in) lines. There is no MISO (master in, slave out) line because the Picaxe chip can only write to the digital pot (as opposed to being able to read from it).

It really has been a productive evening. This would not have been possible without P. H. Anderson's page on using SPI with the Picaxe chips (a true master!). Thanks.

[expand / collapse code]

Saturday, May 19, 2007

Picaxe -> macbook communication...


Using time i should have been spending differently, i whipped up this morning a simple picaxe -> mac thingy. It consists of an 18X, a cheapass Honeybee PSX controller, PS2 -> USB converter and a Max patch. It should be noted that if i didn't have a cheapass, crappy, useless controller at hand then i wouldn't have done this little exercise. It's just a matter of what i have around me, that's all. Call it an effort thing.

In the picture above you can see a pot connected for testing. You could call it pseudo parallel i suppose. Since USB is serial but the actual communication between the picaxe and the psx controller is taking place in parallel, so the data at the Max patch end has to be put back together from serial to parallel.

I couldn't get all 8 bits to work - think this may either have something to do with the crappiness of this controller or with the way that PSX pads operate in general (maybe their buttons operate in a matrix and thus can't see all buttons in a column or row pressed at once or something). Nonetheless it is a step in the right direction.

Below you can see the Max patch. I have been spending a bit of time trying to get stuff working the other way (from the macbook -> picaxe) that i thought it would be fun to try to hack something up to go the other way.

Wednesday, May 16, 2007

Reading 2 pots from 1 pair i/o


So, today i was sitting there and made a quick example of how to read 2 pots using one digital output and one analog input of a picaxe 08M. The idea is to use a relay and the on / off state of the digital output to change which pot's wiper is connected to the analog input. Yep.

The larger IC in between the 08M (at the back) and the relay (towards the front behind the pots) is a 8 x darlington transistor pair (ULN2803A).

I know that this seems too complex for such a thing, but it simply saves using an analog input on a chip such as the 08M (with limited i/o).

As a side-note, here are the colours and pins i am using to program the picaxes - i always seem to forget which is which and it is a waste of time. So i am writing this stuff down...

tip = 3 = ground = orange
ring = 2 = serin = red
sleeve = 1 = serout = brown

Tuesday, May 15, 2007

RS232 scare


The thing is i thought i had blown up my serial port. I was wrong. The way to test this also allowed me to have a little play with a picaxe 08M chip. So all is now good.

Friday, May 04, 2007

Analog signal vs picaxed signal

URL: http://www.youtube.com/watch?v=XPQz1z42tEM
Length: 0:39

This is a follow-on video for the post The full eight bits....

Wednesday, May 02, 2007

The full eight bits...

Since I had a bit more free time, i turned the 4 and 5 bit outputs (seen in the previous post) into an 8 bit output by using more resistors. I made a video demonstrating this by having the 18X sample on one of its analog inputs an audio signal. This data then sets the pins on the output. The effect sounds like a ring mod and a bitcrusher:

"Shows an example of an 8 bit R2R network in place on the outputs of a picaxe 18X.

It's very simple. The guitar is boosted by the preamp pedal. This signal is then fed into one of the analog inputs on the picaxe 18X. This value then sets the state of the R2R "network", which is connected directly to the computer speakers and the oscilloscope. The R2R network is made up of 5% accuracy resistors, so this could cause some noise issues as well maybe.

Anyway, it sounds sort of like a ring mode and a bitcrusher effect put together. I like the sound of the harmonics."

Watch the video here: http://www.youtube.com/watch?v=NnQwen61-Zo
Length is 1:15

Below you can also see pics of 8 bit noise and triangle waves. Yep. This is what i do on my nights off. Really, there's no point to any of this stuff, but you know, it's actually heaps of fun...


Squares, saws and sines

I have had a headache today. To distract myself, I sorted through some stuff and found a bunch of 100 Ω, .25W, 5% resistors. So i decided to see if an R2R network would work using resistors of such poor quality (I have read somewhere that an accuracy of at least 1% at least is needed).

Hooray! It works... sort of at least. Made a sawtooth, triangle at 5 bits and a sine at 4 bits. Actually, the sinewave lookup table (hey, then this is waveform synthesis, eh!) that i used is based upon the waveform on the little sound dj homepage... scroll down on the page... ;-)

I just took some paracetamol. Should be feeling better soon, hopefully.

In the pictures below you can really see the individual voltage values as they refer to the bit depth, especially in the sinewave one. The low bit depths are really a matter of effort... i (think i) have enough resistors to use all eight outputs on the picaxe, but i just wanted see if the whole thing would work.



Thursday, April 26, 2007

18X: Single multi-state send

Another video. This is number three in an "ongoing series" ;P about sending data to the picaxe. First there was a single bit transmission, then nine bit. This one features a single multi-state transition being sent to the microcontroller.

"This movie shows two things based on the concept of sending a single multi-state transition to the picaxe 18x.

a. the control of four independent events. LED's in this case. the keyboard keys Q, W, E and R are mapped to toggle the four outputs of the picaxe on and off.

b. the control of eight co-dependent events. Notes in a sequence in this case. It is a mono sequencer with 16 steps. The pitch values of the notes are set as constant numbers in the picaxe program."

URL: http://www.youtube.com/watch?v=oVBWp1cd1X4
Duration: 1:46

Overview so far...

PLEASE NOTE: This is not supposed to be a finished thing! Just a way to control the picaxe, that's all. A simple way, made up by a newbie! I am sure there are a million better ways to do the same thing.

My code is rough and the hardware is dodge and this way of doing things feels like it's all been gaffed together. But the point is this idea came to me, and I decided to try and make it work, that's all.

Please keep in mind that I have only been working with the picaxe and my own microcontroller programs for a few weeks. Nonetheless, everything that is described here has been actually tested (ie. it's not just theory
), albeit at a *very* slow transfer rate. It is a start. And if that is all that this idea can do, then so be it. It will suit at least some of my needs.


Background

Picaxe microcontrollers (specifically the 18X) are suited to send data to other devices such as over the I2C protocol, one wire interfaces, MIDI output and generic serial data send at baud rates of 300 to 19200 bd.

MIDI input appears to be quite difficult to achieve, and a successful attempt has not yet been documented. Another approach is needed. The aim in either case is to control some aspect of the microcontroller and potentially the physical world from a standard personal computer host system.

Another Approach
A possible next approach in controlling / communicating with the Picaxe is via an audio line that transmits data via a square waveform with a modulating frequency or amplitude. Using an audio line to transmit control data via an audio connection presents certain advantages as well as disadvantages.

The main advantage of using audio to transmit data is that complex and extremely long ‘control programs’ can be recorded and played back from CD audio devices and portable audio devices such as an MP3 player. Furthermore, from a philosophical point of view, the concepts of decontexualisation and symbolism (due to the use of an audio signal as data transfer) can be interesting.

The main disadvantages include the possible slow speed of transfer due to the use of certain commands and constraints and the use of resources that include the engagement of at least one digital to analogue audio converter (a feature that is standard on modern computer systems). However, data transfer / communication via a MIDI connection requires a standalone / external MIDI converter (and therefore represents an additional cost for the user).

1-Bit Data Send
A basic approach to sending some sort of control data to the Picaxe chip is via a simple on/off type command triggered by a change in frequency of a square waveform. Such a setup is perfect for controlling devices with two states, such as relays and LEDs, or for turning a motor off and on at a fixed frequency.

A suitable waveform for such a 1-bit data send is as follows:

The minimum length for Period A and B is approx. 20 to 30ms. The BASIC command SERIN (Serial Input) is used to analyse and differentiate between these two states. The waveforms produce ‘pseudo data’ due to the phasing between the period of a single cycle of the square wave versus the expected data rate by the microcontroller. The highest baud rate at 4.000 MHz is used (2400 bd). 1000Hz returns the value 169 while 1500Hz returns the value 75.

The following BASIC code is suitable for reading a 1-bit data stream:

main:
SERIN 0,T2400,b0
IF b0 = 169 THEN go_low
IF b0 = 75 THEN go_high
GOTO main

go_low:
LOW 0
GOTO main

go_high:
HIGH 0
GOTO main


Single Transition, Multi State Encode
By using additional square wave frequencies, more than just two states can be encoded into a single transition. It appears as though the highest value that can be encoded is a total of eleven states. Other frequencies either return overlapping values with other frequencies or return values that fluctuate between more than two numbers.

The following table contains information based on preliminary experimentation based around the use of different frequencies. The Primary Value and Secondary Value both refer to the data as interpreted by the SERIN command at T2400, 4.000MHz. The term Secondary Value refers to byte values that are returned less often than Primary Values for a given frequency.


Frequency (Hz) Primary Value Secondary Value Logical
3000 153 217 0
2700 199 135 1
2500 255 - 2
2200 192 224 3
2000 28 60 4
1800 102 - 5
1500 75 - 6
1300 165 181 7
1200 85 - 8
1000 169 - 9
700 178 50 10



In order to deduce the logical value of a received serial byte value, a lookdown table comparison is required. Two LOOKDOWN commands are required to compensate for the appearance of the secondary values.

The BASIC code for such an operation is as follows:

SERIN 0,T2400,b0
LOOKDOWN b0,(153,199,255,192,28,102,75,165,85,169,178),b1
LOOKDOWN b0,(217,135,255,244,60,102,75,181,85,169,50),b1



9-Bit Data Encode and Receive
As an extension of the previous two examples, a number between 0 and 511 (9 bits’ worth of data) can be encoded and sent by the computer and received by the microcontroller using three ‘oct’ bits.

To encode the data, a division and modulus chain is used to convert base 10 numbers into three-digit base 8 values. These are then compared with a lookup table that retrieves the correct frequency for a given state between 0 and 7 (ie. base 8).

Furthermore, an ‘on’ or ‘read’ state of $FF as a serial value (a frequency of 2.2KHz) is placed before the three octs. The three oct byte is also followed by an ‘off’ or ‘stop’ frequency of 700Hz.

To reconstruct the original number, the three octs must be multiplied by 64, 8 or 1 (depending on their position in the byte) and then the resultant values must be summed.

The reason for using a three oct byte as opposed to a nine bit byte is to keep the serial transmission as efficient in terms of time and delay as possible. Also, a base 8 number is easier to work with than a base 11 number (which would require a bit more maths on the mcu).

Tuesday, April 24, 2007

18X: 9 bit data transmit / receive

"Here is an example of sending up to 9 bits of data at one time over an audio line to a picaxe 18X chip.

In the movie, only 8 bits are used as the sound command on the picaxe can have the values 0-255.

The data is sent and received as a three oct byte, as opposed to a nine bit byte.

The grid that is shown / played in the movie has a repeating loop (time in steps) on the X-axis and various pitch values on the Y-axis. "

http://www.youtube.com/watch?v=chALSXnuJB8
0:55

Monday, April 23, 2007

18X: led control via laptop

"Another quick example. An audio signal from the laptop tells the Picaxe 18X when to turn the LED on and off.

Note that in the example, the longest period of the LED is well beyond the period of any waveform that a computer could produce (~0.5Hz). The LED could be on or off for as long as the user wishes, or play any pattern. In the example, the smallest period is ~50ms.

Of course, the LED might as well be a relay or something else entirely. And a computer / audio playback device has two channels, so multiple chips or outputs on a single chip could be easily controlled via an ipod shuffle or something similar.
"

Length: 0:20
URL: http://www.youtube.com/watch?v=RmlBfdoE1aE

Friday, April 06, 2007

18X: waveform to pitch mapping

I just uploaded another 18X video. 1:22 long.

"Waveform to Pitch Mapping

A fun little setup. The output from ProTools is connected to an analogue input of the Picaxe. The Picaxe simply has a little program on it that says something like "take the voltage from the analogue in pin, and use that as the pitch of a beepy note". ProTools is running a signal generator RTAS plugin."

http://www.youtube.com/watch?v=ybQ69VkRkuM

Originally, I was going to have a pot to control the tempo of the notes (and therefore waveform sampling interval). But it is far more effective and direct to have it sampling and playing at a constant, quick speed. You can still see in the code that the pot can be connected; the value of adc 0 is being read into byte 0, which ends up as the length part of the sound command. I am sure that the sampling interval would be quicker if I got rid of that now superfluous readadc command... but whether it would sound better is another story entirely...

Here is the code for it:

' ************************************************************
' * using a waveform to control pitch *
' ************************************************************

let b1 = 1 ' set length of sound / sampling interval
main:
readadc 0,b0 ' read the value of pin 0: for tempo
readadc 1,b2 ' read the value of pin 1: for pitch val
let b0 = b0 / 3 min 1 ' set b0 for an appropriate value for note length
let b1 = b0 * 3 / 2 max 255 ' another appropriate note length value
sound 7,(b2,b0) ' play a sound
goto main ' loop forever


Tuesday, April 03, 2007

18X: three examples


So finally, i have had a chance to unpack and muck around with my 18x starter pack. You can watch a quick video of three really basic little things i made just then. These examples are of:
  • a pitched sequencer, where the pot changes the pitch of certain notes in a little loop
  • direct pitch control
  • and tempo control, where the pot is controlling the note length on a minor arpeggio
It's only one minute long.
http://www.youtube.com/watch?v=-zBaQ2rVlNc

Here is the code for the three examples:


' ************************************************************
' * simple adc example to map a pot to sound pitch *
' ************************************************************

let b1 = 1 ' set length of sound / sampling interval

main:
readadc 0,b0 ' read value from pin 0
sound 7,(b0,b1) ' play a sound with length 10ms and pitch from pin 0
goto main ' loop forever


' ************************************************************
' simple adc to control the speed of an arpeggio *
' ************************************************************

let b1 = 1 ' set length of sound / sampling interval

main:
readadc 0,b0 ' read the value of pin 0
let b0 = b0 / 3 min 1 ' set b0 for an appropriate value for note length
let b1 = b0 * 3 / 2 max 255 ' another appropriate note length value
sound 7,(32,b0,48,b0,64,b1) ' play a minor arpeggio whose note lengths are determined by the input
goto main ' loop forever


' ************************************************************
' * simple adc with sequencer where a pot controls pitch *
' ************************************************************


main:
readadc 0,b0 ' read the value of pin 0 and set variable b0 to it
let b1 = b0 + 7 ' create a second variable related to the pin
sound 7,(200,50,b0,25,128,25,b1,50,b0,50,150,25,b1,25) ' play sequence
goto main ' loop forever

Friday, March 30, 2007

Picaxe 18X starter kit


So i ordered a picaxe 18x starter kit. And wow, it arrived today. Congrats, Microzed computing, i am very impressed with your service. It only took 20 hours to arrive from Sydney.