Showing posts with label electronics. PICAXE. Show all posts
Showing posts with label electronics. PICAXE. Show all posts

Electronics - Header pin board

I'm not sure that "because I can" is a particularly good reason to do something, but on this occasion it's all I've got.

I think I'm going to finish my aquaponics demand fish feeder project with a new section of strip board, sticking up at 90 degrees from the main board.

There are these things called header pins that cost a few cents for a stack of them. They are just pins held together with plastic, and you can snap off the number you need. They come in all shapes and sizes and are useful for plugging things into, or turning entire boards into things you can plug into something else.

I used them on my first board (PICAXE 08M ProtoBoard) and ran wires to them from each of the pins, so that I could plug the board into my breadboard.

That's it sticking out of the breadboard at 90 degrees.







I need to add a pot (potentiometer/variable resistor/volume knob) and a light (LED in this case) to flash out the setting for two different numbers. The maximum number of feeds per day, and the size of each of those feeds.

I'm hoping it might look a little better than this piece of paper I have stuck on, but you get the idea.

I also need to add an on off switch to this project.

Electronics - Aquaponics - Demand fish feeder proof of concept

So the aquaponics demand fish feeder works.

Or at least the proof of concept bit works. Not the PICAXE and electronics bit.

The PVC, the motor, the hopper, and the screw all seem to work well together.












It looks like this....



This is just me touching the wires to a battery rather than the electronics triggering this, so the amount it is delivering each time is a little random.

But it will work just fine.

Yay.

Now, where did I put my education. I really need some of it now for the electronics.

I wish I had paid attention in school.

Electronics - PICAXE code

I think I promised I would only write three posts with code.

I think this has to be counted as one of them.

I've been studying hard and also working hard at writing the code for the automatic demand feeder.

I haven't soldered the electronics yet, but I've built each part of it to test it on my temporary breadboard.

This is the bare bones minimum required to make the feeder as lots of the features are not yet complete, and no doubt there are still some errors.

The numbers involved, like the number of feeds per day etc, are very large because I don't feel like waiting for fifteen minutes between tests.

So all the variables are crazy, but from the tests I've done, I think it works.

Even if you have no interest in programming, its worth having a look at it, just to see how your computer actually works.

It looks like this (I'll talk a (very) little about how it works later)...


'-----------About------------------------------------------------------
          'Demand fish feeder ver 02-2011-10-11-1130
'-------------------------------------------------------------------------
'This is an open source project that lives here - http://www.backyardaquaponics.com/forum/viewtopic.php?f=50&t=10587
'and build descriptions that require a lot of photo's live here  -120thingin20years..blogspot.com
'Blame code errors and pecularities on
'BullwinkleII  at backyardaquaponics.com , 120thingsin20years on the PICAXE forum and 'http://ozelecforum.com/, and me at 120thingin20years.blogspot.com ,  
'Special thanks to...
'SABorn at the picaxe forum, and http://ozelecforum.com/
'Steve S at backyardaquaponics.com
'everybody at backyardaquaponics.com, http://ozelecforum.com/, and the picaxe forum 
'Actual PVC feeder device (work in progress (and really only proposed)) can be seen here - 120thingin20years..blogspot.com 
'-------------------------------------------------------------------------
'Uses PICAXE 14M2
'-------------------------------------------------------------------------
'Multi-itask
' Main: (start0) Checks for changed states and calculates  things as required
' Start1:       Checks for lever presses
' Start2:       Reports feeds so far
'-------------------------------------------------------------------------
'This code is provided free to the world without reservation.
'NO RIGHTS RESERVED
'read that bit again before you contribute, but please chip in if you can contribute
'=========================================================

'Variables
{
Symbol w0_DayLengthInMinutes = w0
Symbol w1_RemainderOfTheDayInMinutes = w1
symbol w2_MinimumMinutesBetweenFeeds = w2
symbol w3_ReportFeedsFrequency=w3
Symbol w4_MaxAllowedFeedsForTheDay = w4
Symbol b26_RemainingFeedsForTheDay = b26
Symbol b25_FeedsCurrentlyAllowed = b25
'b24
symbol b23_MinutesSinceLastFeed = b23
symbol b22_NumberOfFeedsNowAllowed = b22
Symbol  b21_LeverLEDState=b21
'-------------Start2 variables ----------------------------
symbol b20_Start2Count = b20
symbol  b19_Start2Count2= b19
symbol b18_FeedsSoFarToday = b18
}
'---------- Here lies everything adjustable ---------
let w4_MaxAllowedFeedsForTheDay =2880    'large number for testing only as I cant wait all day
let w3_ReportFeedsFrequency = 3000       'recomend 15000 = 15 seconds between number of feeds so far today reports
'TODO: feed ammount in fractions of seconds of motor turns
'===========================================
Main:
#simtask all   'for debug only change all to 0,1,or 2 to simulate different multitask threads (not on linux though)
{
'debug
GoSub Init: 'initialize everything required when the device is turned on
GoSub NewDayInit      'initialize everything required to reset for a new day
GoSub OngoingChecks      'main program flow that checks everything continously
end
}
'------------ Main Subs --------------------------------
OngoingChecks: 'main program loop that checks everything continously
{
'debug
GoSub IsFeedingOK    'check if its ok for them to eat
'check for dawn
'check for button press - give them an extra feed override
'check for button press - silulate a days feed
'check for HSM no water flow
'check for HSM water temp is within range
goto OngoingChecks
Return 'never seen
}
'------------------------------------------------------------------
Init: 'used once at system reboot
{
w0_DayLengthInMinutes = 1440    'should be 1440 - populates the variable with the length of a day in minutes
return}
'------------------------------------------------------------------
NewDayInit: 'used at the begining of each new day
{
'debug 'Hi mum let b25_FeedsCurrentlyAllowed = 1
let b21_LeverLEDState = 1
if b21_LeverLEDstate = 1 then High c.4 :endif ' TODO:not sure why this is needed but I was seeing some strange results
let w1_RemainderOfTheDayInMinutes = w0_DayLengthInMinutes
let b26_RemainingFeedsForTheDay = w4_MaxAllowedFeedsForTheDay
let w2_MinimumMinutesBetweenFeeds = w1_RemainderOfTheDayInMinutes / b26_RemainingFeedsForTheDay
let b18_FeedsSoFarToday =  w4_MaxAllowedFeedsForTheDay - b26_RemainingFeedsForTheDay  ' for Start2 report feeds
let time = 0 'reset time to reset minutes since last feed

return}
'------------------------------------------------------------------
NewFeedPeriodInit: 'Used after each feed
{
'debug
let b26_RemainingFeedsForTheDay = b26_RemainingFeedsForTheDay -1
      let b18_FeedsSoFarToday =  b18_FeedsSoFarToday + 1  ' for Start2 report feeds
let w2_MinimumMinutesBetweenFeeds = w1_RemainderOfTheDayInMinutes/b26_RemainingFeedsForTheDay
let b22_NumberOfFeedsNowAllowed = 0 ' dont feed the greedy things just yet
let b21_LeverLEDState = 0 '0 switch off the lever LED
let time =0 'reset time to reset minutes since last feed
return}
'------------------------------------------------------------------
 IsFeedingOK:   'check if its ok for them to eat
{
let b23_MinutesSinceLastFeed = time/60 'calculate  and store the number of minutes since last feed
if b26_RemainingFeedsForTheDay = 0 then return ' bail out of the loop if they cant have any more feeds
endif
if b23_MinutesSinceLastFeed  > w2_MinimumMinutesBetweenFeeds then return ' bail out of the loop if time isnt up
endif
let b22_NumberOfFeedsNowAllowed = 1 'if the program gets this far it means its ok to let them feed
let b21_LeverLEDState = 1 ' turn on the lever LED
'debug
return

'============= End Main ================================
Start1:   'check for lever presses
{
'debug
if b22_NumberOfFeedsNowAllowed = 0 then goto Start1 'no point going further

if pinc.3 = 1 then Gosub Feed
goto Start1}

'--------------Start1 Subs ------------------------------
Feed:
{
'debug
'deliver feed
gosub NewFeedPeriodInit
return}
'============= End Start1 ===============================
start2: 'multitask 2 - loop to  report feeds so far ---------------------------------
'debug
pause w3_ReportFeedsFrequency 'pause for the desired time between each report

if b18_FeedsSoFarToday = 0 then goto FlashZero
b20_Start2Count=b18_FeedsSoFarToday/10                 'isolate tens
for b19_Start2Count2 =1 to b20_Start2Count           'flash tens
if b20_Start2Count=0 then GoTo Remainder
                high c.1   'LED on
pause 800
low c.1                    'LED off
pause 40
high c.1
pause 40
low c.1
pause 780 next b19_Start2Count2


Remainder:
b20_Start2Count=b18_FeedsSoFarToday//10               'isolate remainder
 
for b19_Start2Count2 =1 to b20_Start2Count           'flash units
       
if b20_Start2Count=0 then goto FlashZero
high c.1
pause 200
low c.1
pause 200
 
next b19_Start2Count2
'debug
goto start2
FlashZero:
high c.1
pause 40
low c.1
'debug
goto start2
'==============End Start2 ================================

'TODO: work something out to counter switch bounce if required 

Popular Posts