How do I make solenoids work in Flowcode?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
choppy
Posts: 3
Joined: Sun Mar 01, 2009 9:53 pm

How do I make solenoids work in Flowcode?

Post by choppy »

Hi,

Sorry to disturb you, but I was wondering if you could take some time out to help me.

I am currently developing a system which will allow a user to automatically run a bath at a preset temperature and level. It will be used to reduce the risk of injury to OAPs, children and those with special needs.


I am using the matrix E-blocks components to build the main electronics for the system. I have an Atmel Mega32 microcontroller, which I will use to control 12v solenoid valves to run the the water.

What I am stuck on, is how to control the solenoids using Flowcode – what do I need to do in Flowcode to get the solenoids to switch on and off?

I realise I need to use a relay board and have managed to set the hardware itself up, however I can't seem to find the way to interact with the relay board within Flowcode

Due to the fact that I am the utter definition of a beginner to Flowcode, and have no background in C, it would be benefitial if any solution offered was as easy to follow as possible! :shock:

Thank you for your time and any help would be much appreciated!

Kind Regards,

Choppy :)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: How do I make solenoids work in Flowcode?

Post by Benj »

Hello Choppy

The relay board is quite simple.

I would create the following program to get you up to speed.

Create a loop with a 1 for the parameter/. This will cause the loop to repeat forever.

Inside the loop create two output icons. Make sure they are both pointed to the same port and then change the values so that one outputs 255 and the other outputs 0. Add second delays in between the output icons to slow down the operation. What this will do is toggle the pins on one of the 8-bit ports allowing any relays connected to the pins to be switched on and off.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: How do I make solenoids work in Flowcode?

Post by Sean »

Hello Choppy,

The relay board simply plugs onto one of the port connectors of the EB019 board. The 4-way jumper link on the relay board selects which half of the 8-bit port is used to control the 4 relays.

Any port can be used for this purpose, the selection will depend on the inputs and outputs required for other functions (e.g. all the analogue inputs are on Port A)

Setting the jumper to LOW will cause relays 1,2,3,4 to be controlled by port pins 0,1,2,3 respectively (or port pins 4,5,6,7 when the jumper is set to HIGH).

You can control ouputs using the Flowcode output block.This allowscontrol of full ports, selected pins, or individual pins, using constant values or variables.

I have attached a simple program that should turn RLY1 on and off , for 1 second, continuously when connected to Port B, with the relay board jumperset to LOW

Note: You will need to connect a wire between the +14V terminal on the EB019 board to one of the +V terminals on the relay board to provide the relay coil supply.
Rly1.fcf_avr
(3 KiB) Downloaded 354 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: How do I make solenoids work in Flowcode?

Post by Sean »

the program in the previous post targetted the ATmega644. The version in this post is identical, but targets the ATmega32.
Rly1_m32.fcf_avr
(3 KiB) Downloaded 385 times

choppy
Posts: 3
Joined: Sun Mar 01, 2009 9:53 pm

Re: How do I make solenoids work in Flowcode?

Post by choppy »

Thanks guys! Your replies were extremely helpful! I tested the code on my e-blocks and it works perfectly! Now I need to get to work on integrating this in to my existing flowcode.

Another problem I have been facing is interrupts, or at least I think I need to use interrupts. I have a menu system which displays a looping list of menu options to the user via an LCD screen. The problem occurs when a user wants to select an option. The code to read the users selection (via a keypad) is in a separate macro, which is called after each menu option is displayed on the LCD screen. The issue being that if the user presses a button on the keypad to select their option whilst one of the delay's (used to make the text stay on the LCD screen long enough to be readable) is happening, then obviously it will not be recognised, as the macro that reads the keypad is not active. I hope I have explained that in such a way that it is understandable. :| I think the solution to this problem is to use interrupts so that when a user presses a button on the keypad the macro that reads the button pressed is started.

Sorry if all that is a bit confusing!

Thanks again for your help! I really appreciate it!

Kind Regards

Choppy

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: How do I make solenoids work in Flowcode?

Post by Sean »

Generating interrupts from keypresses is a possibility, but there may be a way to avoid this.

The delay loop that maintains the menu text on the display can be broken down into a sequence of shorter delays executed in a 'while' loop, with a keypad test after each of the short delays. The loop exits if the preset count limit is reached or a key is pressed.

I have attached an example program. The delay loop is between the two comment sections.
keydelay.fcf_avr
(6.5 KiB) Downloaded 385 times
The individual 10ms delays maintain the responsiveness of the keypad, and the loop limit of 1000 provides the 10 second maximum delay (note: the loop limit variable is declared as an 'Int' to allow large values to be used).

choppy
Posts: 3
Joined: Sun Mar 01, 2009 9:53 pm

Re: How do I make solenoids work in Flowcode?

Post by choppy »

Hi.

Thank you so much for the help! It worked perfectly and really helped my understanding of how to solve the issue I was facing. I have made great progress on my project, now I just need to start building the prototype! :P

I really appreciate the help and I'll keep you updated!

Choppy x

Post Reply