Society of Robots - Robot Forum

Software => Software => Topic started by: Zolrag on February 05, 2009, 03:12:01 PM

Title: opto switch
Post by: Zolrag on February 05, 2009, 03:12:01 PM
Hi,
I'm trying to use an opto switch to control the movements of my robot. I use a microcontroler ATmega640.
I'm noob in robotic.
I'd like to write a code similar to this:

include libraries
start of the main function
initialisation of variables      //which variables do I need for this operation?
initialisation of the opto switch    // how to initialise the opto switch? opening the corresponding port on the µcontroler? what is the code?
while(1) (infinite loop)
  if (detection from the opto switch)  //what is the function needed to detect something with this kind of sensors??
     stop motor
     delay for a while
     restart the motor
  end
end

Could you write me a proper code for this application?
thanks a lot
alex
Title: Re: opto switch
Post by: frodo on February 05, 2009, 03:14:53 PM
you're basically asking us to write the code for you. it would be better if someone wrote the code and walked you through it, so to speak. explain the code.
Title: Re: opto switch
Post by: Zolrag on February 05, 2009, 03:19:49 PM
I totally agree with you but nobody I know is able to explain me this so maybe you can do it here....?
Title: Re: opto switch
Post by: Zolrag on February 05, 2009, 03:43:55 PM
Actually I don't really need all the code I just want a function for the detection from the opto swich (something similar to the IR sharp function from the library of avr)
and I need to know how to open the corresponding port to start the opto switch.....
that's all... is it possible to explain me how to do that please?
thank
alex
Title: Re: opto switch
Post by: frodo on February 05, 2009, 03:53:32 PM
oh sorry, i misunderstood  ;D  i have never built a robot so have never programmed so i can't help. sorry!!  :(
Title: Re: opto switch
Post by: Zolrag on February 05, 2009, 03:56:12 PM
It's ok don't worry  ;)  I can program in C++ but it's the first time I built a robot....
Title: Re: opto switch
Post by: frodo on February 05, 2009, 04:10:29 PM
cool. put some pics on when you've finished  ;)
Title: Re: opto switch
Post by: Zolrag on February 05, 2009, 04:12:29 PM
All right I'll do that  ;D if I manage to make the sensors work  :P
Title: Re: opto switch
Post by: Razor Concepts on February 05, 2009, 04:18:25 PM
Could you provide us a link to the opto switch? We need to know how to get the right data from it. If it's just an analog voltage, you can do

int optoswitchreading = a2dConvert10bit(<<insert adc port # here>>);
Title: Re: opto switch
Post by: pomprocker on February 05, 2009, 04:23:51 PM
Could you provide us a link to the opto switch? We need to know how to get the right data from it. If it's just an analog voltage, you can do

int optoswitchreading = a2dConvert10bit(<<insert adc port # here>>);

Yes, datasheets are your friend.
Title: Re: opto switch
Post by: Zolrag on February 05, 2009, 04:30:24 PM
I still don't have the datasheet because it's a project with the university so I have nothing at home and I still don't know what are the details of the sensors but I'll send it as soon as I get the information...
Thanks anyway Razor
Title: Re: opto switch
Post by: Zolrag on February 08, 2009, 04:07:12 AM
Apparently our opto switches are numerical  so you don't need to convert the voltage but I still don't understand how to use it...
We also have micro switches which are actually real switches so it should return 1 if it's switch on and 0 if not (for example) but I don't get how the microcontroler can know when the switch is switched on....What is the function that check the state of the switch???
It must be really easy but I'm getting crazy here....
thx
alex
ps: sorry for all the "switch"  ;D
Title: Re: opto switch
Post by: Admin on February 13, 2009, 01:23:08 AM
Need help and code for the ATmega640 you say?

Have you seen my Axon?
http://www.societyofrobots.com/axon