The PICaxe orrery

Buzby

Senior Member
The orrery is started !

I've got some rough code ready, and the PCB design is almost finished.

( When I find a fabricator who can do it for less than £50 inc P&P I'll order the PCB. )

I originally thought I would need multiple PICaxes, but I've got it down to one 40X2.

It really has been a challenge just getting this far. I've had to write VB to automate the main part of the PCB layout, and more VB to connect the LEDs, and even more VB to create the LED lookup table.

I've found out all the planet's orbital characteristics and squashed them into 16-bit numbers. ( I've got a 32-bit system, it's far more accurate but it runs out of variables too soon, so it only works for 4 planets.

I've experimented with Charlieplexing upto 56 LEDs, the orrery will use nearly ten times as many !.

The PCB layout takes nearly 24 hours to Auto-route.


http://www.doghouse.talktalk.net/partofmypcb.png

It is, as eclectic said, 'a gigantic medieval labour of love', but I'm going to do it.

Here is my rough code :
Code:
#picaxe 40X2

' Orrery

' Hardware 
' 24LCxxx on I2C bus address %10100000
' IR receiver on C.1
' Piezo sounder on C.2

' This project uses a technique which addresses each bit of ports ABCD by using the numbers 0 to 31.
' Addressing IO in this way is not usually needed in PICaxe programmes, but in this case it simplifies
' the code considerably. 

' The Charlieplexed LED matrix is formed from the signals n1 to n24.
' These 24 IO lines can drive a total of 552 LEDs,the Orrery uses nearly all these.  
'   

' Num Port  Leg	Usage                    Num Port  	Leg	Usage
'  0 	B.0 	33	n1				' 16 	A.0 	2	n13 
'  1 	B.1   34	n2				' 17 	A.1 	3	n14
'  2 	B.2 	35	n3				' 18 	A.2 	4	n15
'  3 	B.3 	36	n4				' 19 	A.3 	5	n16
'  4 	B.4 	37	n5				' 20 	A.4 	7	Serout
'  5 	B.5 	38	n6				' 21 	A,5 	8	- 
'  6 	B.6 	39	n6				' 22 	A,6 	9	- 
'  7 	B.7 	40	n8				' 23 	A.7 	10	- 

'  8 	C.0 	15	n9				' 24 	D.0 	19	n17 
'  9 	C.1 	16	IRin				' 25 	D.1 	20	n18
' 10 	C.2 	17	Piezo				' 26 	D.2 	21	n19
' 11 	C.3 	18	i2c				' 27 	D.3 	22	n20
' 12 	C.4 	23	i2c				' 28 	D.4 	27	n21
' 13 	C.5 	24	n10				' 29 	D.5 	28	n22
' 14 	C.6 	25	n11				' 30 	D.6 	29	n23
' 15 	C,7 	26	n12				' 31 	D.7 	30	n24


' Common variables
'Symbol LEDold                 =  W27
'Symbol LEDnew                 =  W26
Symbol I2Caddr                =  W25
Symbol LEDanode               =  B2
Symbol LEDcathode             =  B3
Symbol DisplayDelay           =  W24
Symbol IRval                  =  B4

' Mercury variables
Symbol MercuryCount           =  W23	' Current count value
Symbol MercuryLED             =  W22	' Current LED number

' Venus variables
Symbol VenusCount             =  W21
Symbol VenusLED               =  W20

' Earth variables
Symbol EarthCount             =  W19
Symbol EarthLED               =  W18

' Mars variables
Symbol MarsCount              =  W17
Symbol MarsLED                =  W16

' Jupiter variables
Symbol JupiterCount           =  W15
Symbol JupiterLED             =  W14

' Saturn variables
Symbol SaturnCount            =  W13
Symbol SaturnLED              =  W12

' Uranus variables
Symbol UranusCount            =  W11
Symbol UranusLED              =  W10

' Neptune variables
Symbol NeptuneCount           =  W9
Symbol NeptuneLED             =  W8

' Pluto variables
Symbol PlutoCount             =  W7
Symbol PlutoLED               =  W6


' Mercury constants
symbol MercuryCountPerLED     =     3	' Number of counts per LED 
Symbol MercuryLEDoffset       =     0     ' The starting number for the Mercury LEDS
Symbol MercuryCountPerOrbit   =    64	' The total number of counts for a full orbit.

' Venus constants
symbol VenusCountPerLED       =     5
Symbol VenusLEDoffset         =    24
Symbol VenusCountPerOrbit     =   162

' Earth constants
symbol EarthCountPerLED       =     7
Symbol EarthLEDoffset         =    60
Symbol EarthCountPerOrbit     =   264
 
' Mars constants
symbol MarsCountPerLED        =    10
Symbol MarsLEDoffset          =    96
Symbol MarsCountPerOrbit      =   497
 
' Jupiter constants
symbol JupiterCountPerLED     =    87
Symbol JupiterLEDoffset       =   144
Symbol JupiterCountPerOrbit   =  3131
 
' Saturn constants
symbol SaturnCountPerLED      =   162
Symbol SaturnLEDoffset        =   180
Symbol SaturnCountPerOrbit    =  7777
 
' Uranus constants
symbol UranusCountPerLED      =   309
Symbol UranusLEDoffset        =   228
Symbol UranusCountPerOrbit    = 22260
 
' Neptune constants
symbol NeptuneCountPerLED     =   410
Symbol NeptuneLEDoffset       =   300
Symbol NeptuneCountPerOrbit   = 43507
 
' Pluto constants
symbol PlutoCountPerLED       =   546
Symbol PlutoLEDoffset         =   406
Symbol PlutoCountPerOrbit     = 65496
 
      
 
' Code starts here 
' ----------------

Init:

pause 4000

' Load the LED anode and cathode address details into the EEPROM
Gosub LoadI2Ctable1

' Reset counters
MercuryCount 	= 1
VenusCount   	= 1
EarthCount   	= 1
MarsCount   	= 1
JupiterCount   	= 1
SaturnCount   	= 1
UranusCount   	= 1
NeptuneCount   	= 1
PlutoCount   	= 1



' Main loop
' ---------

Orrery_loop: 
 
' The calculation for each planet is the same
' Decrement the counter. When it reaches zero reset it to the full orbit count.
' Convert the count value into an LED number.
    
' Mercury 
Dec MercuryCount
If  MercuryCount = 0  then	
	MercuryCount = MercuryCountPerOrbit
endif   
MercuryLED =  MercuryCount / MercuryCountPerLED  + MercuryLEDoffset   


' Venus 
Dec VenusCount 
If  VenusCount = 0  then
	VenusCount = VenusCountPerOrbit
endif    
VenusLED =  VenusCount / VenusCountPerLED  + VenusLEDoffset   


' Earth
Dec EarthCount 
If  EarthCount = 0  then
	EarthCount = EarthCountPerOrbit
endif    
EarthLED =  EarthCount / EarthCountPerLED  + EarthLEDoffset   


' Mars
Dec MarsCount 
If  MarsCount = 0  then
	MarsCount = MarsCountPerOrbit
endif   
MarsLED =  MarsCount / MarsCountPerLED  + MarsLEDoffset   


' Jupiter
Dec JupiterCount 
If  JupiterCount = 0  then
	JupiterCount = JupiterCountPerOrbit
endif 
JupiterLED =  JupiterCount / JupiterCountPerLED  + JupiterLEDoffset   


' Saturn
Dec SaturnCount 
If  SaturnCount = 0  then
	SaturnCount = SaturnCountPerOrbit
endif     
SaturnLED =  SaturnCount / SaturnCountPerLED  + SaturnLEDoffset   

                
' Uranus
Dec UranusCount 
If  UranusCount = 0  then
	UranusCount = UranusCountPerOrbit
endif
UranusLED =  UranusCount / UranusCountPerLED  + UranusLEDoffset   

                
' Neptune
Dec NeptuneCount 
If  NeptuneCount = 0  then
	NeptuneCount = NeptuneCountPerOrbit
endif
NeptuneLED =  NeptuneCount / NeptuneCountPerLED  + NeptuneLEDoffset   

                
' Pluto  
' ----- 
Dec PlutoCount 
If  PlutoCount = 0  then
	PlutoCount = PlutoCountPerOrbit
endif     
PlutoLED =  PlutoCount / PlutoCountPerLED  + PlutoLEDoffset   

                

DisplayOrrery:

' This is the Charlieplex code. 
' It lights each required LED one at a time, but does it fast enough to give the impression 
' of continuous illumination.

' The LED is illuminated by setting the two IO pins which are connected to it's anode and cathode. 
' The particular IO pins needed are looked up by using the LED number as the index into I2C EEPROM.    


DisplayDelay = 1000	 ' Length of time to light each LED ( 1000mS for simulation )

I2Caddr = MercuryLED * 2 ' Times 2 because we read 2 bytes back, so we index to twice the LED number 
Gosub ShowLED		 ' Light the selected LED

I2Caddr = VenusLED * 2
Gosub ShowLED

I2Caddr = EarthLED * 2
Gosub ShowLED

I2Caddr = MarsLED * 2
Gosub ShowLED

I2Caddr = JupiterLED * 2
Gosub ShowLED

I2Caddr = SaturnLED * 2
Gosub ShowLED

I2Caddr = UranusLED * 2
Gosub ShowLED

I2Caddr = NeptuneLED * 2
Gosub ShowLED

I2Caddr = PlutoLED * 2
Gosub ShowLED


Goto Orrery_loop		' Repeat indefinately




' Subroutines 
' ------------


' ----------------------------------------------------
' Light one LED for a short time
' ----------------------------------------------------
ShowLED:
	hi2cin I2Caddr, ( LEDanode, LEDcathode ) ' Get the anode and cathode numbers for the LED
	
	High LEDanode	' Turn on the LED
	Low  LEDcathode
	
	Pause DisplayDelay ' Wait a short while
	Gosub CheckIR	 ' Check for IR. ( Do this during the display time, when we are aready waiting. )

	Input LEDanode	' Turn off the LED
	Input LEDcathode
Return

' ----------------------------------------------------
' Check for any IR command received
' ----------------------------------------------------
CheckIR:
	IRIN [1, EndIR], C.1, IRval	' Get value from IR. Timeout after 1ms if nothing received.
	Gosub ProcessIR	' Process any received IR command
EndIR:
Return

' -----------------------------------------------------
' Handle the IR commands
' -----------------------------------------------------
ProcessIR:

	If IRval = 6 then ' Temporary code to stop simulation
	 	end
	endif

Return

' -----------------------------------------------------
' Preset the Anode and Cathode values in the I2C table 
' -----------------------------------------------------
LoadI2Ctable1:

	' Setup the I2C communication to the 24LCxxx EEPROM
	hi2csetup i2cmaster, %10100000, i2cfast, i2cword
	
	' Write the values to the EEPROM
	hi2cout 0,(0,1)	 	 ' LED 0
	hi2cout 2,(0,2)	 	 ' LED 1
	hi2cout 4,(0,3)	 	 ' LED 2
	hi2cout 6,(0,4)	 	 ' LED 3
	hi2cout 8,(0,5)	 	 ' LED 4
	hi2cout 10,(0,6)	 	 ' LED 5
	hi2cout 12,(0,7)	 	 ' LED 6
----
---- A lot of LEDs missed out, forum only allows 10,000 chars per post !
---- PM me if you want the full list.
----
	hi2cout 1094,(31,26)	 ' LED 547
	hi2cout 1096,(31,27)	 ' LED 548
	hi2cout 1098,(31,28)	 ' LED 549
	hi2cout 1100,(31,29)	 ' LED 550
	hi2cout 1102,(31,30)	 ' LED 551

Return
 

Andrew Cowan

Senior Member
What's the PCB dimensions? Hopefully someone on here will have some experience with a cheap manufacturer and you'll find a price under £50...

A
 

Buzby

Senior Member
Dimensions are about 8" x 11", roughly the size of an A4 sheet of paper.

I've found an e**y seller in the UK who will do 144 sq in for £50 inc P&P.

I just need to check they can do the size I need, not just little boards paneled many times.
 

Buzby

Senior Member
Board arrived !



First error - Holes for programming jack are too small. I must learn to review the details better.
 

Buzby

Senior Member
PCB was from a UK seller http://www.sticklebackuk.com/circuits/

I'm very pleased with it. The only problems I can see are ones of my own making. It was my first PCB design, so I've learned to double check the hole sizes !,

The next step is to get the 24LCxxx and IR receiver working.
 

Buzby

Senior Member
24LCxxx working fine. IR receiver released some magic smoke. I don't think the pinout was the same as the RevEd supplied version !.

Put some temporary LEDS in, and a bit of test code, hid the lot behind a piece of paper, and here are Earth and Mars !.

http://www.doghouse.talktalk.net/IMGP2833.AVI TalkTalk have shut down my webspace !. I'll try to find another and repost.

Brightness levels need adjusting, and the rotation speeds are wrong, but the principle is working !.
 
Last edited:

Buzby

Senior Member
Just a quick update. The 144 LEDS for the first four planets are in, but I might change Earth, they are a bit dim. The Infra Red remote control is working, it just changes the speed up and down at the moment. Now I'm in the middle of re-writing the calculations to use 32 bit, because 16 bit is just too rough, even for driving such a low resolution display.
 

Buzby

Senior Member
Wow, I am impressed !.

I've got the code to calculate the orbits and select the LEDs down to a measly 229 bytes, with 23 words of variables.

Coding is linear, no indexing or arrays, and is accurate to around 0.002% for the inner planets, worst case 0.21% for Pluto.

It's fast, no sign of flicker due to Charlieplexing, and Mercury can orbit in less than a second.

I just need to solder in the remaining 400 LEDs before we can see what it really looks like.
 

Buzby

Senior Member


Here are 528 LEDs driven from a single 40X2.

( The three things that look like 16 pin ICs are 8 way resistor packs, not driver ICs )

Now I need to get some good video so you can see it in action.
 

John West

Senior Member
If you mod the layout so all the non-LED components are on the backside of the bd, you can drop all of the LED's flush with the bd and make soldering all those little devils much easier.
 

Buzby

Senior Member
Yes, I thought of that as well, just as I was soldering LED number 342, or was it 423, I can't remember !

In fact it would not need a PCB mod, just a software change.

The whole idea of this project was to see if Charlieplexing would work with so many LEDs, the hardware could have done with a bit more thought. ( Hindsight is a wonderful thing ! )
 

John West

Senior Member
All in all, I'd say you proved that beyond a shadow of a doubt. Well done. In fact, I'd say the whole project is well done. Good stuff.
 

Buzby

Senior Member
The Orrery project has gone on the back burner again, but here is the code so far.
It may be useful if anyone wants to see how I did the planet calculations and the Charlieplexing, or has a better idea how to do it.

There are two files, one each for Slot 0 and Slot 1.

EDIT - See later for files
 
Last edited:

Jamster

Senior Member
Wow... I go away for a little while and look at the progress...

Makes my 50 LED RGB fader look a bit rubbish... :D
Jamster
 

Buzby

Senior Member
Hi Jamster,

Thanks for the comment, but don't say your 50 LED fader is rubbish.
If you learnt something from making it then it's worthwhile, no matter what it is or what it looks like.

( The Orrery display doesn't 'look' as good as I wanted, http://www.youtube.com/watch?v=82LvqiaH-iA , but the Sparkley and the LHC look great. ! )

This was a project to see if I could calculate planetary orbits accurately, and Charliplex hundreds of LEDs, using just one PICAXE.

Now that I've proved it can be done I've lost interest. There's so much more the Orrery hardware can do, if it's programmed to do it. I will eventually get round to building a case and hanging it on the wall, as was the original intention, but I don't think I'll spend much more time on the software.

This has always been one of my problems.
Once I've proved my ideas will work, I never seem to get round to finishing things off.

Cheers,

Buzby
 

Jamster

Senior Member
All I can say is that that video is remarkably awesome!!!

Might be trying some Charlieplexing (or maybe just multiplexing) in the near future so will use the resources here. :)

Jamster
P.S. And yes, the fader is rubbish because it never worked properly in the first place... :)
 
Top