​ ​ ​ ​ self-organizing systems with many picAXEs
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 34

Thread: self-organizing systems with many picAXEs

  1. #1

    Default self-organizing systems with many picAXEs

    Hi all,

    I've been reading something over at instructables that triggered my interest: an array of LEDs simulating the self-organizing behaviour of a swarm of blinking fireflies. The LEDs start out by emitting random flashes of light, but with time they synchronize to each other and finally they all blink synchronized (each of the LEDs has a small Atiny12 and a light-dependent resistor) Since I like the idea I want to copy this with several picAXE08 (I don't like atmel chips since I can't write code for them).

    But before going out and buying a whole bunch of picaxe08, I thought I'd like to have some opinions on the software I wrote for it - specifically my fears are that the individual "fireflies"/circuits will not differ enough in their initial delay before they start their blink'n sync adventures..

    I've tried to fill a word variable with "random" value and then use only 1 byte of that, can anyone have a look at the code please and tell me what they think - will this cause the fireflies initial (still unsynchronized) behaviour to be "individual" enough, or will the more or less all start at the same time?

    Will the program work at all?

    thanks

    heres my code

    Code:
    ; *** FIREFLY.BAS  ************ Version 1.0 beta *******  SELF-SYNCHRONIZING NETWORK OF LED FIREFLIES  ***
    ; this program is intended for simulation of a swarm of fireflies by many individually controlled LEDs, designed
    ; to run on a PICaxe08 with a LDR connected to pin 1  and one LED wired to pin 2 (each firefly needs one PICaxe)
    ; Since they are totally independent besides of sharing the same reset switch, one can easily combine any number of 
    ; fireflies to form a large array of blinking, self-organizing LEDs...  pressing the "reset" switch will of course disturb 
    ; the fireflies and their uniform blinking pattern, like walking right into a swarm would disturb real blinking fireflies too, 
    ; probably, and it takes awhile before they start blinking and syncing again...
    ; --------------------------------------------------------------------------------------------------------------------------------------------------
    ; Copyright (c) 15/05/2009 
    ; Dennis Schulze
    
    ; variables
    symbol Power = w4               ;determines how urgently the firefly wants to pulse or how hard it "desires" to do so 
    symbol Brightness=b2          ;this later contains the reading of the LDR value
    symbol Ambient =b3             ;initial ambient light intensity value is stored here for comparison reasons
    symbol BlinkCounter =  b4    ;Counter needed for initialisation blinking loop
    symbol RndDelay = b1          ;this will be seeded with a random number for individual delay time
    
    ; constants
    symbol Daylight=195              ; above this light intensity threshold the firefly does not glow at all (i.e. if its not "night")
    symbol MaxPower = 80        ; Urgency threshold that triggers an immediate pulse
    
    ;counters
    let BlinkCounter = 1                ;reset all counters
    let Power = 1			;
    
    
    ;randomize a bit to give individuality
    random w0                          ;generate "random" 16bit number (hopefully differing enough between individual PICaxe ICs)..
    let RndDelay = b1 * 24        ;take the last 8bit of it and multiply by 24 to give several seconds delay at most
    
    
    ; initialisation blinking loop
    for BlinkCounter = 1 to 5    ; blink five times
    	gosub pulse
    	pause 700
    	BlinkCounter = BlinkCounter + 1
    next BlinkCounter	
    
    
    
    
     pause 1500                            ; wait long enough to make sure that absolutely NO firefly is blinking at the moment
    readadc 1, Ambient             ; then read out ambient light intensity and store value in "Ambient"
    pause RndDelay                     ; pause for an "individual" (hopefully) amount of time before doing anything else
    
    
    
    main: do        ; main loop
    
    
    	
    	let Power = Power + 1     ; slowly start incrementing the fireflie's desire to blink..
    
    	
    	readadc 1, Brightness     ;...while watching the surrounding fireflies too!
    
    	
    	if Brightness >= Daylight then      ; unless its daytime (fireflies are sleeping during daytime!)...
    
    		sleep 3
    
    	endif
    
    	
    	if Brightness > Ambient then       ;......perceiving pulses from other fireflies will
    
    		Power = Power + 50             ;..strongly increase our fireflys desire to pulse with them!
    
    	endif
    
    	
    	if Power > MaxPower then          ; if the desire is strong enough... 
    
    		gosub pulse		; ...the firefly bursts out a light pulse
    			
    	        let Power = 1         ; what a relief for the firefly! "desire" is reset to initial value 
    	        				; (equals satisfaction about just having pulsed) 
    	  
    	 endif
    
    				
    loop       ;  starts building desire for another pulse again (while slowly approximating the other's frequencies)
    
    
    
    
    
    ;subroutine
    pulse:
    
        high 2             ; give a short flash of light
        pause 300
        low 2
    
    return

  2. #2
    Moderator
    Join Date
    Jan 1970
    Location
    North Norfolk blow-in.
    Posts
    6,129
    Blog Entries
    1

    Default

    @Dennis

    "Will the program work at all?"

    Have you tried it?
    If only in Simulation.



    e
    Last edited by eclectic; 16-05-2009 at 20:33.

  3. #3

    Default

    Not in hardware since I don't have many spare picaxe08 lying around, which is prerequisite for this project.

    The program does simulate well though, the "LED" flashes from time to time while slowly incrementing the "desire" by 1 at a time, when I raise the adc value manually this triggers the LED to flash almost immediately which is what it should do.

    I'm only concerned about diversity between single chips: will a number generated individually on each chip with "random" differ enough between single picaxe08 to make it possible that they all start at different times when all are switched on at once? They should not be synchronized at the beginning already thats why I ask. The effect is that they need some time to get into sync with each other.. ..looks very interesting when you watch it.

    But for this to happen, they need to be off-sync to begin with. This is achieved by having each "firefly" wait an individual amnt of time before it starts blinking and syncing. So a good random value is needed for calculating this individual delay. the Picaxe08 doesn't have any internal clock the random number could be seeded with (like with the picaxe X chips), but I hope their internal oscillators are all slightly different enough. (?)

    anyone know code for generating good (diverse between single chips!!) random numbers?
    Last edited by AlC; 16-05-2009 at 20:42.

  4. #4
    Moderator
    Join Date
    Jan 1970
    Location
    North Norfolk blow-in.
    Posts
    6,129
    Blog Entries
    1

    Default

    Here's a starter thread.

    http://www.picaxeforum.co.uk/showthread.php?t=7799

    Afterwards, perhaps consider randomised "Start" timings
    for the 08(M) chips?

    e

  5. #5
    Senior Member
    Join Date
    Jan 1970
    Location
    Shropshire, UK
    Posts
    2,265

    Default

    Interesting !

    I've not studied it in detail but - If you're powering up all picaxes at the same time then I think you'll need to have a different 'seed' for the random part, becuase it's only pseudo random on a picaxe. However I'd personally not get hung up on the random aspect and just have different preset constants for each picaxe.

    Also, you might find the LDRs have trouble detecting the light pulses from the LEDs??

    So, what stops real fireflies all speeding up I wonder?! Do they have an inbuilt frequency?

  6. #6
    Senior Member
    Join Date
    Jan 1970
    Location
    UK
    Posts
    3,043

    Default

    To get truly different delays, put pause 3 at the top of one 08Ms code, pause 7 at the top of the next's, pause 11 at the top of the next...

    A

  7. #7

    Default

    Use the LDR to get the first random number seed.
    War is Peace. Freedom is Slavery. Ignorance is Strength.

  8. #8
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,316

    Default

    All PICAXE random numbers will initialise to zero and follow the same sequence so all ( without any attempt to synchronise them ) will run in sync until small differences in oscillator frequencies causes them to drift apart. You will need a seed value which is different for each PICAXE programmed.

    One way to create a seed is to read the initial value from Eeeprom, update it and write back. This way you get a different sequence at each power-up. Unfortunately all those powered up the same number of times will stay in sync.

    You can get a random value from reading the LDR as Boriz suggests, and you could add this to a stored Eeprom value.

    Eeprom 0,(0) ' Initial seed - All the same

    StartProgram:
    Read 0,w0 ' Read initial seed
    ReadAdc10 1, brightness
    w0 = w0 + brightness
    Random w0
    Write 0,w0 ' Save a new seed for next time
    Do
    : ' Rest of code
    Loop

    There are other ways to do it; you could read the LDR value and repeat 'RANDOM w0' however many times indicated and so forth.

    Note that PICAXE-08 only have limited ADC capabilities; only 16 distinct levels. You may be better off with 08M.
    Last edited by hippy; 17-05-2009 at 01:11.

  9. #9

    Default

    Assuming you have an unused input could you record a few bits from a floating input pin and use this as the seed? I've not got a clue as to how well it would work though.

  10. #10
    Senior Member
    Join Date
    Jan 1970
    Location
    Shropshire, UK
    Posts
    2,265

    Default

    Or perhaps just have the picaxes in two groups each group (flock/swarm?!) fed from a different power switch. Then manually switch each set on with manual delay between switching - I'd think this would ensure each display sequence would be sufficiently different??

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •