Jump to content

driving a relay without dout


Recommended Posts

temporary return from midibox retirement.. i will come back soon.. but too busy right now doing other stuff.. however right now i have a little project where i want to ultimately drive 2 strobos with midi and i thought i could build it with midibox.. without realizing that i have been absent from the community for about 4 or 5 years.. luckily i still have a core_r3 lying around.. but my knowledge is dated and rusty.. and i have a specific deadline of a week.. yeah im insane.. but i think i can, i think i can, i think i can... *yeah, just keep repeating that.. that'll work*

so, i did a quick search.. and i know i've kinda asked it before (but with leds the other time)

is there a way to drive a relay without using a dout.. i just need to switch a signal from low to high, whenever a specific note comes in.. i dont have a DOUT lying around.. so i kinda wanna make it work without harvesting it from my already built gear..

i guess i just need 4V from a digital out pin somewhere, but last time i checked (5 years ago) there is no option in MIOS to drive a digital pin directly.. anyone an idea?

Link to comment
Share on other sites

ive written some beginners code for mios before so, its not a problem if i need to write it myself(famous last words :S) however i need the right code to command the pins to do what i want.. but if its possible within the MB_CV then i should be able to do it aswell.. hopefully the CV isnt written in ASM.. cuz that stuff is way beyond me..

maybe someone knows of some example code? i didnt find it.. but maybe someone did?

Link to comment
Share on other sites

You can pretty much use any open pin on the PIC for that. There's a neat demo-app that uses J5 and lets you write to it as if it were a DOUT shift register. Careful though, relays typically pull more current than a pic pin can safely supply - using a transistor per relays is definitely a must.

Link to comment
Share on other sites

In circuits I`ve seen that drive relays from microcontrollers, usually a darlington optocoupler is used. In addition to preventing an overload, it isolates the signal from the (inductive) coil, protecting the microcontroller from back-EMF ringing/surges.

Link to comment
Share on other sites

these are definitely some good suggestions.. so i'll be in need of some optocouplers.. gonna need to find an electronics store nearby.. my idea was to use some kind of resistor in series with the relay to limit the current..

here is the datasheet:http://www.produktinfo.conrad.com/datenblaetter/500000-524999/505395-da-01-en-HALBLEITER_REL_1S_15_A_250_VDC_AQA211VL.pdf

for the relais i'm planning to use.. they say its a MAX of 20mA for the input current.. i wonder what would happen if i put in a led and resistor in series though.. as for back emf and stuff like that.. isnt that for mechanical relays.. this one is AFAIK solid state relay, or however they are called..

as for that demo app.. nils.. would you happen to have a link to that? would love to get my hands on it..

Link to comment
Share on other sites

Welcome back! :)

I would propose to use Reed Relays instead (see also this picture: http://www.ucapps.de/mbhp/mbhp_doutx1_reed_relays.jpg - the relays are connected to a shift register here, but could also be directly connected to PIC pins of course)

Current consumption is low, and no additional components are required.

Available at Reichelt (SIL 7271-D 5V) for 1.40 EUR

The demo application can be found under: http://svnmios.midibox.org/listing.php?repname=svn.mios&path=%2Ftrunk%2Fapps%2Fexamples%2Fasm%2Fj5_dout%2F

A precompiled binary is available under: http://www.ucapps.de/mios_download.html (search for j5_dout)

Note that a J5 driver is available which would allow you to access J5 pins from C code as well: http://svnmios.midibox.org/listing.php?repname=svn.mios&path=%2Ftrunk%2Fmodules%2Fj5_io%2F

And here the example which explains how to access any pin from C: http://www.ucapps.de/mios_c_pic_pin.html

Best Regards, Thorsten.

Link to comment
Share on other sites

Hey TK! glad to be back! thank you for the example code.. its exactly what i was looking for!!

these reed relays are a good idea.. however ordering from reichelt would take way too long, and i would have to order for 100 euros at once.. i did have a look around to see if i could find it in one of our electronics stores.. and i did find some dual in reed relays/normally closed.. but i needed to by 25 of them..

i took a closer look at the datasheet for the relays ive already ordered.. and from what i can gather.. they already have an optocoupler in them.. these are pretty expensive relays.. solid state.. a led already on them, to show the state.. and i have no clue what a varistor is.. but they have it too.. im guessing they'll either be perfect for what i want to do with them, or it'll go horribly wrong.. either way. it'll be fun..

So the last thing is putting it all together.. i'll keep this thread updated.. and ultimately (when i have more time, i.e. a deadline that is more than 3 days away) i'll build a final box with 8 outputs and some cool code to automate stuff.. and ofcourse i'll post it all on the forums..

Link to comment
Share on other sites

well, the thing is finished. and on time i must add..

the example code was exactly what i needed, i didnt even have to adapt it.. thnx TK!!!!

the relays i had work perfectly.. no opto or extra relays needed..

ill post some pictures later..

Link to comment
Share on other sites

  • 8 years later...

I do hope nobody minds me resurrecting this ancient thread. I finally started on that 8 out relay thing (9 years, damn!) i've mostly got the hardware built.
But i've been halted by bit of an issue.

i've uploaded the j5_dout example hex to my core8, but the core8 doesn't seem to react to the midi note c4->c5 that i send it through mios studio. i've tried measuring it with my multimeter, and an oscilloscope, but only got 0v on the pins.

the core announces itself dutifully through Mios Studio, so i know the core is working. I've got multiple cores lying around, so i tried it with another one as well.

What am i missing?

ps. sorry for the lack of pictures, as a meagre solace, here is the one i'm currently building.


Link to comment
Share on other sites

  • 3 months later...

After coming back to this issue every once in a while (real life stuff keeps popping up) it just occurred to me that I was most likely using older pic processor back then. in the mean time i've ordered a pickit from ali. Once I find a bit of time, i'll go through my older pic processors to see if I still have an older one. and see if i'm able to program it with the bootloader.


Link to comment
Share on other sites

  • 2 weeks later...

i am just stupid, that's what the issue was, or more like i was a bit conceited. thought i could pick up where i left off and have all my knowledge intact..

i FORGOT to upload the MIOS hex first.... yep, that IS dumb..

alright. so now, i'm facing other issues. i keep getting errors when uploading mios to some of my pics. i got just one of my 18f452 pics to accept mios.
cool, so i have 1 pic that should work. but when i plug the mb_core into the header of the relay board, only 7 relays are working. not 8.

so pin testing time, only 7 of the 8 pins output 5V. weird. bad PIC? alright, lets try my hand at programming the bootloader on one of my virgin 18f352, pickit3. nope. borrowed pickit2. nope.. oh hey an old 18f4685 in my stash, with bootloader!!! alright lets upload mios to that one..

success!!! buuuuut... only 7 of the 8 pins outputs 5V. WTF???

possible causes.
issue: 1 relay doesnt switch.

Could it be a faulty relay?
- no, inverting the sil socket cable, moves the issue to another relay.

Faulty cable?
- could be, but testing directly on the mb_core shows that that specific pin wont give 5v.

bad pic then?
- maybe, but 2 different types of pic have the same issue on the same pin.

Bad mb core PCB?
- no, tried multiple, besides i've measured continuity.

Bad source code - i'm not willing to believe TK wrote it incorrectly and didn't tested it, but for a learning experience let me see if i can check it with my limited knowledge.... nope it's mostly in assembly as far as i can tell. got as far as the function  J5_IO_PinSet which can be found in the j5_io.inc file. dope, but it has more than 8 pins listed there, but it seems to forward those pins to the other pins if certain conditions are met. pin numbers seem to be in WREG, couldnt find that though. and even then, i wouldnt know what to do with it.

TL;DR - found a solution for the problem in my previous post (i was dumb), new issue, pin a0 on j5 won't output 5v after booting like the other pins, and doesn't react when sending C4 to the MB_core, the other pins work like expected.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...