Step 9: Serial communication

To make the pet door controller communicate with the OpenWrt router you must connect the controller's TX pin to the router's RX pin and the controller's GND to router's GND (In our situation the communication is one way, from the controller to the router).

First of all, comment (add # in front of them) the lines in /etc/inittab :

tts/0::askfirst:/bin/ash --login
ttyS0::askfirst:/bin/ash --login
tty1::askfirst:/bin/ash --login

this will disable login console terminal on serial port, so we can use it for back and forth communication with the arduino based controller.

Both the router's serial port and controller's serial port must have same speed to be able to communicate. The router's serial speed to is set to 9600 by executing:

root@OpenWrt:~# stty 9600 < /dev/tts/0

For each RFID tag read by the pet dor controller, the controller will write to the serial the RFID tag with .txt at the end of line, for example, if the tag is 01068E2081, and the pet went out the door (breaking the IR beam) the controller is going to write to the serial 01068E2081-out.txt and if the pet went in the door (door opened by the RFID tag), the controller is going to send over the serial 01068E2081-in.txt

On the router, to read what's coming over serial communication from the controller, your code should look something like this:

# Tell the AVR we're ready to start doing stuff
echo "start" > /dev/tts/0
while true # loop forever
  inputline="" # clear input
  # Loop until we get a valid command from arduino
  # the line should be the text file we have to open to get
  # a random message
  until inputline=$(echo $inputline | grep -e ".txt")
     inputline=$(head -n 1 < /dev/tts/0)

by looking for .txt we will know when we got a new command from the pet door controller.

After we got a new command, for example 01068E2081-out.txt, we are going to read a random line from the file with the same name:

LINES=`wc -l $inputline | awk '{ print ($inputline + 1) }'`
RANDSEED=`date '+%S%M%I'`
LINE=`cat $inputline | awk -v COUNT=$LINES -v SEED=$RANDSEED 'BEGIN { srand(SEED); i=int(rand()*COUNT) } FNR==i { print $0 }'`

take a picture from the Webcam:

ln -s /dev/v4l/video1 /dev/video1 # create /dev/video1
spcacat -d /dev/video1 -g -f jpg -p 10000 -o > /dev/zero # take a picture every 3 sec

and upload them to twitter (twitpic):

# tell curl to send a multipart form to twitpic
# save returned XML in a variable
RET=$(curl -s -S -F "$myname" -F "$pword" -F "$cargo" -F "$tweet" $target)
echo "$RET"

Note: In this project the communication is just one way, the OpenWrt router just receives messages from arduino based controller. If you want to communicate both ways, in your bash script on the router use following command to send messages to arduino based conntroller:

echo "test message sent from OpenWrt router to arduino" > /dev/tts/0

<p>Now I finish the blog where I put all my work related to WiFi Radio. It can be reached at: machiuka.blogspot.ro. </p>
<p>Today I finish the final version of my internet radio. A brief presentation is available on <a href="https://www.youtube.com/watch?v=G3dQMRIbTWI&feature=youtu.be" rel="nofollow">https://www.youtube.com/watch?v=G3dQMRIbTWI&amp;feature=youtu.be</a>. I hope to have the time to make a blog with this project. I'll keep you informed. </p>
<p>Finally I've solved the connection problem, between MR3020 and Arduino ProMini 5V, through 3,3V FTDI breakout. Arduino ProMini communicate with router on ttyUSB0. It is shown typing &quot;dmesg&quot; command.</p><p>Pinout are:</p><p>FTDI 3,3V Arduino Pro Mini 5V</p><p>GND -&gt; RAW</p><p>CTS -&gt; GND</p><p>3V3 -&gt; Vcc</p><p>TX0 -&gt; RX0</p><p>RX0 -&gt; TX0</p><p>DTR -&gt; DTR</p><p>Now I'm able to finish my WiFi Radio with internet time clock and IR remote control.</p><p>I'll keep you updated!</p><p>P.S. Am scris in engleza fiindca pagina ta este vizualizata de foarte multi si poate informatiile astea (care m-au costat 3 zile de munca) sunt utile cuiva.</p>
That's good! In glad that you figured it out.
<p>Ajutooor! De doua zile ma chinui sa realizez o comunicare seriala intre Arduino si ruter. In final am reusit sa comunic prin portul USB (/dev/ttyACM0). Am insa o problema. Pentru a definitiva proiectul trebuie sa inlocui Arduino Uno cu Arduino Pro mini. Am incarcat aplicatia din Arduino Uno in Arduino Pro Mini, am facut legatura prin USB la FTDI (RX FTDI &lt;-&gt; RX Arduino, Tx FTDI &lt;-&gt; Tx Arduino), dar nu reusesc sa mai comunic cu ruterul. Nu vede FTDI-ul de nicio forma. Care sa fie diferenta intre degatura seriala de la Arduino Uno cu ruterul si cea de la FTDI si ruter? Uno merge, dar Pro Mini nu (nici direct nici prin FTDI). Am instalat mod-usb-serial-ftdi dar degeaba. Multumesc anticipat! (P.S.)Am un FTDI de 3,3 V si un ProMini de 5V, pe care l-am alimentat separat prin USB din ruter. Nu cred ca e problema aici.</p>
Sincer sa fiu nu stiu care poate sa fie problema. Eu nu am mai lucrat cu Arduino sau cu OpenWRT de cativa ani. Ce trebuie sa verifici e ca FTDI-ul si ProMini-ul au pamantul connectat si ca vitza e setata la fel pt TX si RX.
<p>Scurta intrebare Ioan: de ce ai atribuit lui START si STOP anumite valori (i.e. 10 si 15)? Multumesc si imi cer scuze pentru stupizenia intrebarii. </p>
START=10 - inseamna ca ruleaza dupa scriptul cu START=9 sau mai mic, dar inainte de scriptul cu START=11 sau mai mare<br><br>STOP=15 - la fel, dar pt stop. ruleaza dupa scriptul STOP=14 sau mai mic si inainte de STOP=16 sau mai mare. Valoarea asta e optionala.
<p>Multumesc pentru lamurire. Am inteles.</p>
<p>Incerc de cateva zile sa realizez o comunicare bidirectionala intre OpenWRT si Arduino. Nu am reusit decat una unidirectionala, intre AVR si OWrt sau invers. Am facut un WifiRadio dintr-un satellite receiver si am nevoie de 2 lucruri pentru a utiliza front panelul original de la satelit: transmitere sir de 4 caractere reprezentand ora exacta de la OWrt la AVR, pentru a fi afisate pe display (lucru realizat cu EtherShield library si functional acum) si transmitere sir de 4 caractere intre AVR si OWrt, reprezentand coduri de telecomanda (realizat cu EtherCard library dar inca neimplementat). Vazand tutorialul tau ma gandesc ca ar fi mult mai simplu sa utilizez comunicarea seriala prin USB pentru a realiza ambele lucruri cu acelasi AVR. Pana sa-ti vad tutorialul ma gandeam sa folosesc 2 AVR, fiindca biblioteca IR perturba integratul ce comanda displayul (4 digit 7 element common anode). Ce parere ai? Multumesc.</p>
Hi pdxnats &amp; Fun2hold comments earlier. Congratulations, I believe have something quite special here. You may not realise but you may have a seed of an idea here that may have far reaching consequences. Here you have a building block to advancing AI (Artificial Intelligence)<br><br>I better explain briefly (bear with me): You have given your lovely moggy a way of communicating with the whole world, without even realising it herself. AI is of no use socially if it does not interact with us or animals. Now, I'm not too sure where this is going, however I do know that I have lots of ideas for this concept that could make your moggy talk to the world in a more expressive and articulate way. Drop me a message with your mail address, It would be fun to talk.<br><br>ps without doubt, an all time best instructable with potential that could blow your mind!
I COME from China ,I can't understand whato you say ,but i love eletrion <br>中文,你能看懂吗,有会中文的网友吗?
This is just awesome. Not only is it a very well written instructable, but it involves hacking a router and creating a standalone twitter-enabled sensor-camera. I haven't tried building it yet--I'm a little intimidated by it--but this is the best example of its type I've seen. Thanks for posting it!!!
Thank you. If you have questions or some details are not clear, let me know.
Well, my enthusiasm is dampened by the outcome for those two poor cats -- so sorry! The Great outdoors is not at all great for innocent beings who are at the mercy of anyone or anything that comes along (The word ManKIND is far too often an Oxymoron). A tamper-proof cat enclosure- good idea-- but letting your cat out? The world has changed alot-- it's like letting your 2 yr old out without supervision.
I can assure you we were responsible pet owners. By no means would I equate cats to a human child regardless of how much our cats meant to us: ) Our cats had wonderfully full lives being indoor/outdoor. Gus passed away likely due to an encounter with a predator, a very natural death for an animal and Penny passed due to old age. The cat door offers solutions for pet owners with a multitude of obstacles and needs for their pets; indoor and outdoors.
Not only is this awesome, but I NEED IT NOW!!!<br><br>I've been waiting for a manufacturer to make an RFID cat door. (mind boggles as to why it still does not exist). And here you have just handed it to us, thank you.<br><br>One million percent awesome!
Thank you!
RFID pet doors have existed for years. For cats and dogs. The modification here is to make it tweet as well as unlock the door for your pet. Imagine how practical as well as fun. My husband is afraid to let the petdoor unlocked when we are not home, even if the yard is fenced. &quot;We never know&quot;. Whit this system, we can monitor the dog's coming and going and monitor how long they spend out. If it seems too long (they never go longer than half an hour in the summer and 5 seconds in the winter) I can call the old lady neighbor or a friend and ask to check on them.<br><br>What I am waiting for is a RFID door I can easily program to scan the RFID chip already imbedded in the dog's skin in case it gets lost/found. I bet e1loan can figure it out...? :)
Yes I suppose I knew that those existed, but I didn't try very hard to find one. I looked on Amazon but they only have those ones that require the cat to wear a heavy awkward dangly magnet. My cat goes collarless so I haven't bothered with those.
There are about a half dozen commercially-made RFID doors, some fancier (and more expensive than others). I installed one that reads the sub-q embedded microchip for each of our two cats.
What's the fun in buying stuff if you can make it yourself and learn a lot in the process?
Exactly !!<br>
You are absolutely right and I am absolutely lazy.
You are not the only lazy one!<br><br>I suppose to redeem myself I should hack in to the flap I've bought to add tweeting and data logging of entry/exit times :)
Oh! What is the brand? I can't find one. Does it work well? Does it let the cold/hot in when it is closed?
I don't know of a product that would work for implanted chips in dogs. The reason the one for cats works is because they have no problem going in a door not much bigger than their head. I have a SureFlap, but there are others. The cat has to put it's head into the &quot;chute&quot; in order for the sensor to detect the chip. It requires very close (1-2 inches) of proximity.
Oh, that is *awesome*! Our cat does not wear a collar (ever try to get a collar on a highland lynx?), but does have the chip embedded in his body, this is perfect!
Am I the only one who is troubled by the sad connection between letting cats out &mdash;unleashed and unsupervised&mdash;and &quot;Gus died a while back (probably a fight with a raccoon or other cats?) and not long after, Penny followed&quot;? <br><br>
Not all cats fare equally outdoors. My neighbors cats have been indoor/outdoor cats for well over ten years, no problem. A lot of factors to consider.
Stats show &quot;indoor&quot; cats live twice as long (on average) as in&amp;out cats; pretty straightforward.
Gotta love people who love to CONTROL their pets. Have you ever heard of quality-of-life? I could probably make sure you lived to be a hundred. Daily enforced exercise, extreme calorie restriction, no dangerous activities, etc. But you wouldn't stand for it. Why would you impose it on animals? Because it makes your little control-freak heart happy. Oh, and you get to be holier than thou all over everyone else...
Here in Australia, it's more important to control cats because they are a significant threat to native wildlife, and less about the safety of the cat. Cat owners, it should be illegal to allow your cat out at night. Your cat's well-being is not more important than the well-being of the native birds it will kill while they sleep.<br> <br> Besides, there's nothing worse than waking up to find that your neighbour's good-for-nothing cat has urinated all over your front door mat. That says 'Welcome to my house' in a distinctly unpleasant manner.<br> <br> With all that in mind, I am thinking of making one of these for my neighbour, only instead of a switch controlling the lock, it would be time based to prevent the cat from getting out at night.
I have a fenced yard. The dogs can't go in. But if a raccoon wanted to come in, it could easily. I am not pro letting cats roam free willing either, but I wouldn't go around pointing fingers. Sometimes we do things that we think are ok, and then somethings happens and make us realize it was a mistake. (Ever try to light up a fart at 15 or something stupid like that?)<br><br>That said, here is a picture of the stray we took in last winter. He was in very bad shape, but just the nicest. Sadly, he didn't make it; I wish he had come to me earlier. R.I.P Skinny Jim.
I'd like more information about supervising a cat outdoors. Is that possible?
I wasn't gonna get into this debate, but I actually have a response to this. I take my indoor cat out on a harness. She doesn't mind a bit- I don't &quot;walk&quot; her as much as she walks me and I try to pretend like I'm not there. She climbs, scratches, sniffs, and has a great time.
No problem, I've seen that before. I was wondering if those were discrete actions. As in you could supervise w/o a leash or harness. <br /><br />I let my cats out and they often don't even come back at night. Don't mind others keeping cats indoors, just their choice.
I guess we do kind of do that with our other cat, actually. He is young, and timid &amp; skittish by nature. He doesn't like the harness at all, so we just take him outside our front door and put him down and watch him. It's not really enclosed but there are only two easy escape routes which we sort of causally guard- once again the idea is to sort of pretend we're not there and let him do his own thing while enjoying the outdoors. He is naturally nervous so he doesn't run off or climb up anything or try to escape, just sniffs at things and rolls on the ground in the sun and other cat things. <br><br>I'm not one of those people who sees this issue in black and white, either- I just decided to keep my cats in because my neighborhood is not cat-friendly, they don't seem to mind mostly staying inside, and they get tons of exercise playing with their humans &amp; each other. <br><br>To the original poster sorry about all the OT chatter :D
How about recognition software for the camera to bar entrance when kitty is trying to bring in something vile?
<a href="http://www.quantumpicture.com/Flo_Control/flo_control.htm">Here you go</a>:
You could put an electronic scale at the entrance and see if your pet is heavier than normal :-) (of course you have to consider the extra weight when your pet is wet)
With the use of a humidity sensor, you can then have an acceptance weight range, and hence no problems. Just a thought.;-)
... and if the scale is one of the clear glass kind, you could install a scanner under, to take a picture of your pet's feet to see if they are dirty or not :-)
I have constant problems on a large and expensive scale because my neighbors let their cats roam loose. Well, one cat now, coyotes got the other cat a few months back. <br><br>So cat owners, PLEASE, keep your cats under control! Us dog owners manage it, so can you. Besides, death by being torn apart by a coyote or a raccoon would be horrifying, can you imagine dying that way? I can't, and I sure wouldn't want it for my pets either.<br><br>But otherwise, this is a pretty awesome 'ible!
Very nice. I'm getting to like this rfid stuff. Would be a great way for a robot to identify its location or access areas of a house. I've been thinking about writing an 'ible on motion based webcam/email security system. Maybe I'll do that. As for the cats, our cat was in and out often until finally he just stays outside except to eat etc. He hasn't expired yet. (We do live in the country though)
Hey.....this could work for the kids, too! <br>
Great project. If you'd like to build on it, I have suggestions. <br>1. Many cats come equiped with an RFID chip installed by the Vet. How about designing your invention to work on these chips? <br>2. Enable different in-out settings for 2 or more cats. <br>3. Logging ability: Produce a log of when kitter goes in and out. <br> <br>Thanks for this project!
This is a fantastic project! Who doesn't love the Arduino, and is there anything it can't do? I lack many of the genius skills I read about here in Instructables, but my dream project would be a cat food bowl RFID device. With two cats, one always eats the other cat's food. We have one skinny cat, and one not-so-skinny cat. <br><br>Outstanding job friend!!!

About This Instructable


134 favorites


More by e1ioan: Grape Arbor Rubberband Handgun Teardrop Trailer
Add instructable to: