Please point me to some step by step basics to code the PICAXE using Blockly.

Gramps

Senior Member
The hard reset worked well! thank you.
Question, must you program a pin to be an input or an output? Where would I find this question answered in the manual? Thanks, Gramps
 

Gramps

Senior Member
Please refresh my memory.
Each arm of the LED array is controlled by two pins.
Do both pins go high to turn on the designated LED?
Thanks, Gramps
 

ZanderPIC

New Member
To detect when the hammer is down simply use a laser and LDR. when one of the hammers comes down it'll block the laser and thus the LDR will increase in resistance. Simply monitor the ADC of the LDR.

P.S - The laser will be positioned so if any hammer is down it will be blocked. This has a draw back of not knowing if the correct hammer was pressed.

Cheers, Zander
 

AllyCat

Senior Member
Do both pins go high to turn on the designated LED?
No, one pin (the Anode) must be taken High and the other (Cathode) pulled low, so that current flows through the diode.

If both pins were at the same voltage, no current would flow, therefore no light output!

Cheers, Alan.
 

Gramps

Senior Member
Thanks Alan for clarification.
Zander, what is an LDR?
We thought about lasers earlier, Or at least infrared sensors. How would you position them so the entire keyboard was covered?
Yes it would be much better if we did not have any hardware on the hammers.
Which hammer is used or which string is hit doesn't matter. We just want to detect that a note was played.
 

lbenson

Senior Member
Last edited:

ZanderPIC

New Member
Since hammers are hand-held, their position when striking is not fixed, so (easy) detection by laser would not work.
We thought about lasers earlier, Or at least infrared sensors. How would you position them so the entire keyboard was covered?
Yes it would be much better if we did not have any hardware on the hammers.
Ahh yes the laser idea will not work, although I've got another (hopefully not covered yet). If the wires are conductive then attach some tinfoil to the hammer which is +5V then connect and pull down all the strings with a 10k resistor; the strings will also connect to one pin on the picaxe. The idea is when the hammer contacts any string it'll pull the picaxe pin high.

The downfall to this is I'd assume the tinfoil would affect the sound. Furthermore, the strings may not be conductive.

Cheers, Zander
 

lbenson

Senior Member
The strings are surely conductive, but if he was willing to have wires to the hammers, he could use the accelerometer.
 

Gramps

Senior Member
As much as I like low-tech solutions, the accelerometers really sound like a cool way to do this :)
The 28 x 2 arrived this week, as well as some breadboard jumper wires. Still waiting for accelerometers from China.
 

techElder

Well-known member
A hammered dulcimer has upwards of 30+ notes spread over a larger area than most stringed instruments.

Having said that, I’m sure an electromagnetic sensor could be developed that spanned the strings to detect strikes.
 

Gramps

Senior Member
The piezos would probably work, but would we need fifteen pins to spread them all over the instrument?
 

lbenson

Senior Member
The piezos would probably work, but would we need fifteen pins to spread them all over the instrument?
I don't think so. With a guitar, you only use one (I don't mean the kind of pickup which has 6 sensors). You don't need to distinguish notes, just determine that a strike has caused vibration which the piezo converts into an electrical impulse.
 
Last edited:

Gramps

Senior Member
All these sensors are inexpensive so we plan to try several different kinds to see what works the best. We have a prop scope that's been sitting in the box for years might be a good time to test it out.;-)
 
Last edited:

Gramps

Senior Member
lbenson, Help!
When attempting to run your accelerometer code from post 135, we're getting a syntax error at:
readadc10 C.1,w1 ' read "Z" axis of XL335 accelerometer
Here is the code:

#picaxe 28x2
#no_table
#no_data

; =======================================================
; Sequencing 7 LEDs to an XL335 accelerometer
; =======================================================

Symbol D4 =B.7
Symbol E4 =B.6
Symbol Fs4= B.5 ;F#4
Symbol G4 =B.4
Symbol A4 =B.3
Symbol Be4 =B.2 ;B4
Symbol C5 =B.1
Symbol hammer =pinC.1


main:
do
readadc10 C.1,w1 ' read "Z" axis of XL335 accelerometer
if w1 < 380 then ' acceleration towards a strike
sertxd(#w1," ")
pause 200 ' reduce/eliminate double reports
endif
pause 5
loop
 

premelec

Senior Member
"Error: Pin C.1 has no ADC channel!" use a pin that has an ADC channel... there are 10 such pins refer to Manual 1
 

Gramps

Senior Member
Thank you. That fixed it.
Question, what is the best way 2 program the LED array?
Each LED has two pins to activate, pulling one low and one high.
How do we code that?
 

premelec

Senior Member
Put negative LED to V- and + LED lead to output pin through 220 ohm resistor. Use HIGH and LOW commands to turn LED on/off. See Manual 3 for interfacing details.
 

Gramps

Senior Member
Right i understand that but in this case we have 16 LEDS connected in an array going to 8 pins. To light an LED we must tell one pin to go high and another pin to go low. Must that be two separate commands?
 

premelec

Senior Member
I don't know how you have them connected - assuming only one being on at a time - likely you can turn on on one with HIGH, other with LOW and both off by changing pin to an input... pseudo tri-state pin...
 

techElder

Well-known member
Gramps, you are going to create a "translation table" perhaps using a spreadsheet or simply use a notepad. This table contains musical notes for the program and output bits that produce the correct combination of output pins to make each note's LED light up.

List your musical notes (assuming LEDs represent these notes) on lines from top to bottom to make sure you are representing all notes that you want.

Next to each note you could simply list an 8-bit number that represents the note in your program hopefully represented in a SYMBOL statement e.g. "SYMBOL Asharp = 12". This is your index into the following output bits for the output pins.

The next column is where the magic happens (read that tedious programming :D). Decide which bit in an 8-bit byte will represent a particular output pin. This is the "translating" part. For each note by using binary representation (show zeros and ones), determine which output pin(s) have to be HIGH and/or LOW to make the LED for that note light up.

By doing this translating (from inputs to outputs) you have created a table that makes programming much easier. Your program won't change if you move your LEDs around or add LEDs or etc. You just change your output pin translation! I'll tell you who taught me that ... HIPPY! :D

With this information, you can create several ways to to make it work depending on speed requirements, but one way is using a LOOKUP statement. Other ways include SELECT/CASE, or a bunch of IF/THEN statements. I'm sure there are other ways.
 

hippy

Technical Support
Staff member
Right i understand that but in this case we have 16 LEDS connected in an array going to 8 pins. To light an LED we must tell one pin to go high and another pin to go low. Must that be two separate commands?
In general it will require two separate commands, though if one of the pins is already at the level required you would only have to alter the pin which isn't.

That is more likely to be the case when multiplexing a matrix to control more than one LED at a time. A particular set of cathodes may be set low and then you would only need to cycle through setting anodes high. For setting one LED and leaving it set two commands would be required for that.
 

lbenson

Senior Member
Sorry, Gramps, I didn't see your post from 7/10.

See post 44 (and 47) for the 28x2 code and translation table I used for the matrix, in particular:

The possible hammered dulcimer notes are shown in the comment line below, and the encoding for the LEDs in the line following:
Code:
' G3,-G#3,A3,-Bb3,B3,C4, C#4,D4,-Eb4, E4,F4, F#4,G4, G#4, A4,Bb4,B4, C5, C#5, D5,-Eb5,E5, F5,F#5, G5,-G#5,A5,-Bb5,B5, C6,-C#6,D6
'$00,$FF,$01,$FF,$02,$03,$10,$C0,$FF,$C1,$11,$12,$C2,$13,$C3,$20,$C4,$C5,$21,$C6,$FF,$C7,$22,$23,$C8,$FF,$30,$FF,$31,$32,$FF,$33
In the encoding, "$FF" means not available (as does "-" in the first line), "$C0-$C8" means pins C.0 through C.7 and A.0 (for the 9 notes which occur more than once), and other values indicate which pins in portB are activated for the appropriate LED in the 4x4 matrix. Each matrix-indicating byte value is made up of 2 nybbles, each of which may have a value between 0 and 3. The high nybble I've assigned to the anode (positive) side of the led, and will bring high B.0, B.1, B.2, or B.3. The low nybble will have 4 added to it so that it refers to B.4, B.5, B.6, and B.7 (one of which will be brought low). The non-selected high nybble and low nybble pins are tri-stated (made inputs)
 

Gramps

Senior Member
Thank you again for the detailed instructions!
We still need to purchase an LCD screen.
Which one should we get?
 

lbenson

Senior Member
We still need to purchase an LCD screen. Which one should we get?
It's hard to say. As far as I can tell, all the "serial" LCDs and OLEDs on the first few pages of Amazon (which you might get quickly), or ebay are actually I2C (TWI) two-wire modules, and I don't think you have the pins available, especially the default port B pins (though you might be able to bit-bang it on other pins (which you still don't have available)).

Rev-Ed's true serial OLED is here: http://www.picaxestore.com/index.php/en_gb/picaxe/add-on-modules/axe133y.html

That might be your best bet, though I would still consider a 40X2 on a breadboard so you would have plenty of free pins. Then you could use the inexpensive I2C or SPI modules.
 

Gramps

Senior Member
Yes there are not enough pins on a 28x2 to do this project. So we are scaling it back and going to use 8 notes to get started, D4, E4, F#4, G4, A4, B4, C5 and D5.
Using a magnifying glass I think I have found the nine correct pins and the ground on the education board.
this really looks like it would be easier to do if the chip was directly plugged into the project workspace rather than trying to use the education board.
After we get that working, we'll get a 40 pin chip.
 
Last edited:

lbenson

Senior Member
... we'll get a 40 pin chip.
Alternatively, you could use an i2c i/0 expander like the MCP17008 (for 8 pins) or MCP17016 (for 16 pins). That would take away C.3 and C.4--hi2c scl and hi2c sda--but would enable you to use an i2c display without taking up additional pins. The 40X2 would make for cleaner code, though.
 

Gramps

Senior Member
We made a wiring error on the 9 LED array. We grounded the Anodes instead of the cathodes! Pins B0 through B7 work the other way. Is there a way to reverse the direction of the DC on the pins or must we rewire the diodes?
 

lbenson

Senior Member
If I understand correctly, all you would need to do is reverse the HIGHs and LOWs. So in the code in post 44, after "else ' portB LED matrix control--", replace "high pinNo" with "low pinNo", and "low pinNo" with "high pinNo".

(Maybe I misunderstood--do you mean on the 16-LED matrix? If not, I would think you need to rewire. Alternatively, you can take the common wire from all the Anodes to +5V, and the cathode wires to the individual pins (through resistors). Then the "active state" for each pin would be "LOW" instead of "HIGH"--"tri-state" the inactive pins by making them inputs.)
 
Last edited:

Gramps

Senior Member
(Maybe I misunderstood--do you mean on the 16-LED matrix?)
Nope. As you suspected it is the 9 pins that connect to the eight diode pairs and one diode triple.
It appears the simplest thing to do will be to physically reverse the 19 diodes. (crying)
 

hippy

Technical Support
Staff member
We grounded the Anodes instead of the cathodes! Pins B0 through B7 work the other way.
It is not clear exactly what you have done. If you have grounded the anodes then the only way current could flow through a LED to illuminate it would be if the output drive were at a negative voltage ...

Code:
      |    ___    K   A
  X.Y |---|___|----|<|----.
      |            LED   _|_ 0V
 

lbenson

Senior Member
(Maybe I misunderstood--do you mean on the 16-LED matrix?)
Nope. As you suspected it is the 9 pins that connect to the eight diode pairs and one diode triple.
It appears the simplest thing to do will be to physically reverse the 19 diodes. (crying)
If you have all the anodes commoned together and going to a ground point, can you not cut the connection to ground and instead make one to +5V? Then the cathodes go individually to the appropriate C0-C7,A0 pins, and are activated by taking the pin low? (This actually follows a suggestion made, I believe, by Allycat many posts ago, because a picaxe pin can safely sink more current than it can source.)

A clear photograph might help.
 

Gramps

Senior Member
Actually unsodering the diodes was pretty easy. All 19 of them are now tested and correct.
We grounded all the strings on the dulcimer and taped a thin wire to one of the hammers. It is giving us a very reliable signal to our input pin.
The downside is having a wire on the hammers. Hopefully an acoustical pickup will prove to work.
BTW, those cool little accelerometers arrived yesterday. Have not yet had a chance to experiment with them
 
Last edited:

Gramps

Senior Member
Question, is there a list of needed parts to use a pic on a breadboard?
We have a download cable and would need a breadboard adapter.
 

lbenson

Senior Member

Gramps

Senior Member
Thank you.
this code will not light an LED across pins b1 and b6. Why?
#picaxe 28x1
#no_table
#no_data

main:
do
high b.1
low b.6
pause 1000
low b.1
high b.6
pause 1000
loop
 

Buzby

Senior Member
Absolutely nothing wrong with that code, must be a wiring issue.

Please post some pictures.

Cheers,

Buzby
 
Top