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

Gramps

Senior Member
Great. (Now I wonder what other tunes use only the notes you now have available.)
There are several more songs in the hymnal we can play.
The new breadboard is in the mail so hopfully we can soon set up the 40 pin chip and the 35 lamp array we built before our trip this summer.
 

lbenson

Senior Member
Twinkle didn't want to run on the simulator with the 28X1 chip. Don't know why.
The bptr variable is not available on the older 28X1 chip. Hippy's code using eeprom and READ would work.

I didn't have the assignment of notes to pins right. Try this:
Code:
' 28Twinkle
#picaxe 28x2
symbol _D=B.1
symbol E=B.2
symbol Fs=B.3
symbol G=B.4
symbol _A=B.5
symbol _B=B.6
symbol Cs=B.7
symbol DD=B.0
' Twinkle, Twinkle, Little Star
poke 56,_D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, _A,_A,G,G,Fs,Fs,E, _A,G,G,Fs,Fs,E, _D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, $ff
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : low @bptrinc : Pause 100 : loop until @bptr = $ff
 

lbenson

Senior Member
Wow. Great. Thanks. Looks like I left out an "_A" note at "Like a". Try again.
Code:
' 28Twinkle
#picaxe 28x2
symbol _D=B.1
symbol E=B.2
symbol Fs=B.3
symbol G=B.4
symbol _A=B.5
symbol _B=B.6
symbol Cs=B.7
symbol DD=B.0
' Twinkle, Twinkle, Little Star
poke 56,_D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, _A,_A,G,G,Fs,Fs,E, _A,_A,G,G,Fs,Fs,E, _D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, $ff
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : Pause 100 : low @bptrinc : loop until @bptr = $ff
Is the first note lacking a repetition?
 

Gramps

Senior Member
"left out an "_A" note"

yes and we have to hit the doubled notes twice. Can you make them blink?

"Is the first note lacking a repetition? "

No, just forgot to hit it twice!
 

lbenson

Senior Member
Hmmm . . . Once again I forgot to move the pause after the LOW statement. This should blink. Increase the pause if need be.
Code:
' 28Twinkle
#picaxe 28x2
symbol _D=B.1
symbol E=B.2
symbol Fs=B.3
symbol G=B.4
symbol _A=B.5
symbol _B=B.6
symbol Cs=B.7
symbol DD=B.0
' Twinkle, Twinkle, Little Star
poke 56,_D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, _A,_A,G,G,Fs,Fs,E, _A,_A,G,G,Fs,Fs,E, _D,_D,_A,_A,_B,_B,_A, G,G,Fs,Fs,E,E,_D, $ff
bptr=56 ' above top named variable 
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : low @bptrinc : Pause 100 : loop until @bptr = $ff
 

lbenson

Senior Member
I think this one approximates "Simple Gifts":
Code:
' 28SimpleGifts
#picaxe 28x2
symbol _D=B.1
symbol E=B.2
symbol Fs=B.3
symbol G=B.4
symbol _A=B.5
symbol _B=B.6
symbol _C=B.7
symbol DD=B.0
' Simple Gifts
poke 56,_D,_D,G,G,_A,_B,G,_B,_C,DD,DD,_C,_B,_A,G,_A,_A,_A,G,_A,_B,_A,Fs,_D,_D,G,Fs,G,_A,_B,_C,DD,_B,_A
poke 90, G,_A,_A,_B,_B,_A,G,G,G,G,DD,_B,_A,_B,_C,_B,_A,G,_A,_B,_B,_C,DD,_A,_A,_B,_A,_D,G,G,_A,_B
poke 112, _B,_C,DD,_C,_B,_A,_A,_B,_B,_A,G,G,G,$FF
bptr=56 ' above top named variable
do : high @bptr : Do : Loop Until pinC.0 = 1 or pinC.1 = 1 : low @bptrinc : Pause 100 : loop until @bptr = $ff
Not certain that I counted everything right.
 

Gramps

Senior Member
Here's a rendering of simple gifts

Pin B. 0 is burned out on our chip so High D does not play

. We're not familiar with the tune so not sure if it sounds right or not.
 

Gramps

Senior Member
It seems like Hippie said something one time about changing all the pins to inputs if you wanted to use two pins to control One LED.
Ironing the bugs out of the matrix this morning and it's working correctly.
 

lbenson

Senior Member
If you have, say, a 4x4 matrix with 16 LEDs, then to light a single LED, one pin of the high 4 will be high, one pin of the low 4 will be low, and the remaining pins should be tri-stated (made inputs on the PICAXE). If you have two LED reverse-paralled for each of your matrix connections (32 total LEDs), then you don't have a specific HIGH or LOW side, so of your 8 outputs, you would make 6 inputs, one high, and one low.

For instance:
pinsB=%00000000 ' all portB pins are tri-stated (inputs)
high B.7 ' this turns on the "reversed" LED at this intersection
low B.1
 

Gramps

Senior Member
"you have, say, a 4x4 matrix with 16 LEDs, "
Yes, that's correct.

"the remaining pins should be tri-stated (made inputs on the PICAXE). "

Just one line of code to tri-state the entire program?

What about pins D.2 through D.6? (nine pins) We're using them as outputs to the other LEDs.....
 

lbenson

Senior Member
Quite a rig you have there.

If you have a 4x4 LED matrix with 16 LEDs (i.e., no "reversed" LEDs) and using 8 pins (e.g., B.0-B.7), then you only need to tri-state the pins which are attached to the matrix which are not set either HIGH or LOW to drive the single LED which you want to turn on.

Whenever you light a new LED, you need to make sure that you have tri-stated the 2 pins which were used to light the previous LED. Rather than keep track of which pins those were, and individually setting them to inputs, the easiest thing is just to tri-state the whole port with "dirsB=%00000000" and then set the desired pins, e.g., HIGH B.0 : LOW B.7.

The other pins which light single LEDs--D.2-D.6, etc.--only need to be set LOW to turn off their LEDs. However, you can alternatively turn them off by tri-stating them, e.g. INPUT D.2.

Do you have 4 resistors on the pins on, say, the high side of the matrix?
 
Last edited:

lbenson

Senior Member
B4 B5 B6 and B7 have the resistors going directly to the pins
Is that the high side?
Depends on what commands you have to issue to turn on the LED. If you turn on an LED by taking B.4 or B.5 or B.6 or B.7 HIGH and one of B.0-B.3 LOW, then that is the high side. If you take one of B.4-B.7 LOW, then that is the LOW side. It doesn't matter whether the resistor is on the high or low side. If you have resistors on B.4-B.7, you should be good.
 

Gramps

Senior Member
"Is this the way to connect this accelerometer to the chip?
Connect vcc to 5 volts+, ground to ground and the "Z_out" to pin C.1? "

The data sheet on this chip says the operating voltage is 3 volts but the advertisement on the website says it will run on 3 or 5 volts?
Is 5 volts ok?

Can we add the OLED module to our code after we get the note player working or do we have to make provision for it now?
 
Last edited:

lbenson

Senior Member
"Is this the way to connect this accelerometer to the chip?
Connect vcc to 5 volts+, ground to ground and the "Z_out" to pin C.1?
The data sheet on this chip says the operating voltage is 3 volts but the advertisement on the website says it will run on 3 or 5 volts?
Is 5 volts ok?"
Can't say for certain. When I tested, I'm pretty sure I was powering the picaxe off of AA batteries, but not sure whether it was 2 AAs or 3 AAs.

Can we add the OLED module to our code after we get the note player working or do we have to make provision for it now?
You can add it later--no problem for code, but make sure that your hardware arrangement can accommodate what you want to do.
 

Gramps

Senior Member
In this code B.1 is high and B.6 is low and note F#4 lights
next note B3 flashes, then F#5 lights

but B1, B7 are flashing also. Why?

Is it because we don't have it tri-stated correctly?

#picaxe 40x2
#no_table
#no_data
pinsB=%00000000 ' all portB pins are tri-stated (inputs)

main:
do
high b.1 'note F#4
low b.6
pause 1000
low b.1
high b.6
pause 1000

high b.0 'note B3
low b.6
pause 1000
low b.0
high b.6
pause 1000

high b.2 'note F#5
low b.7
pause 1000
low b.2
high b.7
pause 1000
loop
 

lbenson

Senior Member
You have to tri-state the port with "pinsB=%00000000" each time before you set a new note (LED) in the matrix so that you turn off the previous LED.

In this code B.1 is high and B.6 is low
Your code actually has that reversed--B.1 goes low and B.6 goes high.
 

Gramps

Senior Member
This code WORKS!
THANK YOU lbenson!
main:
do
high b.1'F#4
low b.6
pause 1000
pinsB=%00000000

high b.0'B3
low b.6
pause 1000
pinsB=%00000000

high b.2'F5
low b.6
pause 1000
pinsB=%00000000

loop
 

Gramps

Senior Member
Why does Hippy's code run in the simulator but not on a chip?
Tried it on a 40x2 and a 28x2. ???


Data ( B.6, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do
High b1
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low b1
b0 = b0 + 1
Read b0, b1
Loop Until b1 = $FF

OH! Had data turned off!!! DUH!!!
 
Last edited:

Gramps

Senior Member
How to get a pause between two notes that are the same?
EDIT:
We added a pause.......
Is this the best way to do it?
Does this place a 250 pause before each note, slowing down the program?
Thanks, Gramps

Data ( B.5, B.5, B.4, B.4 )
Data ( $FF )
b0 = 0
Read b0, b1
Do : Loop Until pinC.0 = 1 or pinC.1 = 1
Pause 100
Low b1
b0 = b0 + 1
Pause 250 'Added pause here and it works!
Read b0, b1
Loop Until b1 = $FF
 
Last edited:

lbenson

Senior Member
When writing code for the 40x2 and the 28x2, are they the same except for different pin capacity?
Right. And regarding "hardware arrangement", I would recommend leaving C.3 and C.4 available on the 40X2 so that you can use I2C eeprom for storage as needed (and its also possible to use an I2C display).
 

Gramps

Senior Member
"hardware arrangement",
Here's the "NEW" plan using the 40X2 chip
C.0 and C.1 for inputs,
Kept open C.2 and C.3
A.4, A.7 and C.6 are unused
All the other pins (25) are outputs to LEDs.
This way we can eliminate the matrix.....
 
Last edited:

Gramps

Senior Member
Question, is there a way to make the simulator chip window larger? We see how to magnify a part of the chip but can't see it all the pins at one time .
We see the control now, thanks
 
Last edited:
Top