Mostrando entradas con la etiqueta Arduino. Mostrar todas las entradas
Mostrando entradas con la etiqueta Arduino. Mostrar todas las entradas

jueves, 30 de abril de 2015

Write and Read RFID

The practice is to schedule an RFID card with a certain code that is common between cards.
To do this we must first program the cards and we need an RFID reader. We must first understand how these cards work, is an issue of a certain frequency, this frequency emission of the card is driven by a magnetic field generated by the RFID reader so that when a certain distance card reader, the card can emit that frequency and the reader depending on what we indicate now may accept or reject the card.
The materials need is the Arduino UNO card, RFID reader and cards.

image
Then we will have a brief description of the practice.
Read a card that works for RFID protocol read the identifier key A, read the result identifier Key B, which is the password that comes from the trailer factory located in each sector.
Once that is done to modify prompted the sector number to write and the block number. You can write in several blocks at a time but this example is done with only one block. This will block the password you want in numbers 0-255.
In our memory it is displayed in hexadecimal format. This practice is done because the UID (ID factory) can not be changed by this method. The card used is MFRC522 which has a 1K memory.
It has 64 blocks of 16 bytes. For each sector we have 4 blocks, block most weight is the one with the identifier and the other blocks serve as increment and decrement purse.
In block 0 sector 0 we have the ID card is unique and provided by the manufacturer. We can also see that there is a password on each sector located in block 3 of each sector, which can be modified, although it is not recommended as it can cancel the card and not to modify it while we used to compare the UID.
The protocol for this practice is SPI.
First we begin to explain how to program the cards. I connection.
image
SPI include the library and the MFRC522 card is used. We define the pin 10 as a slave pin and pin 09 as a reset, and declare a function to associate MFRC522 library what the SS and RST pins are.
image
Now for the setup, we started to see the serial data, the SPI protocol, started the MFRC522 reader and print as a control point.
image
Now is the loop. We created the object key (key that is inserted at the factory and is in every trailer block) the class is MFRC522 factory. For we identify with begins at byte 0 to 5 and are 0xFF. The IsNewCardPresent this serves only read a card because if we put two data pile up.
ReadCardSerial this serves so that if he was present and was reading not bunch up.
Then you choose the field of 16 there. The block number you put a name in this case valueBlockA and dedicated to block password block.
imageNow the reader must identify the data of the default password. First start with the key A. Status gives a value of 1 or 0, which makes authentication is the first thing that comes out of the class in this case is the key A, you say in that block is the key and the MFR. UID is the bookstore. It returns a value 0 if it goes below the authentication communicating, in the same way about the factory key B failed.
image
Now we will indicate what kind of key you want. Serial.print indicating create a text that shows us that will start recording our new key card. We create a byte constant size and is an array with the data we record we can write in the 16 fields in the array. The status returns 1 if written with this function, the first value we place the block number, followed by the constant and the number of data recording.
We record the effect of a Serial.print card.
imageNow we see a confirmation of having successfully recording the key. If you are not well recorded the message "La has cagado grabando" if we recorded well as leave the message "Has grabado Flaman". Then to display the data by the pour Serial data by serial to confirm that I recorded, the first thing is the UID, followed by the key and the entire sector, there are functions inside the library to display the block that we have recorded, or the whole card. Halta puncture this feature sends to terminate high transfer and would request if StopCrysptol card and is a function that the process ends.
image
Well we finished recording the card now is that we can read the card and give us the way to such a gateway.
The connections are the same what changes is the Sketch.
As explained below is performed for reading. Include the SPI libraries and MFRC522 as explained above, the SS and RST pin function library to determine the SS and RST pins, our key is an array and must be equal to that put to record cards otherwise it will not give way. I put two LEDs green and one red or refuse to make way for determining which is digital five green and red el`pin digital pin 4.
image We started with the setup, we start the Serial, SPI protocol, the MFRC522 card, print the serial we are waiting for a card, determine output LEDs and are therefore in low off.
  image
Now for the loop. In the same way it is explained above is the protocol, first compares the key factory, if one is present card and if you are reading a card that does not bunch up.
We say that buffer is byte data type and is 18 bytes. Choose the sector, you have 16 sectors. The block number you put a name in this case dedicated to block valueBlockA password block.
 
image
We identified as explained above.
image
Now let's read in block 4 of the sector 1, determine the size for what we have in the buffer. We print the serial we are reading the card. Status returns Mifare_Read which determines the function returns 1, the first value put the block number, followed by the buffer, and the number of data to read.image 
With this for what we do is determine which index 0-16 go one by one. Reading print buffer to create the MIFARE_Read function and will put a 0 in front. Pass the index variable data to hexadecimal. We print the index in managed print the serial block read.

image
Compares the first and second byte and card reader. If it is all right because it indicates a text of "Pase hacia delante" and the green LED lights up intermittently.
image Otherwise shows "Prohibido el paso" and flashes the red LED.
image If status returns 0 determines you have not read well and put the following "The've screwed up reading", and instead as  “lectura correcta”
image And the end is the same as in the recording.
imageI attached two videos so you can see how it works by reading serial.

To download the files from all the practice you must click on the picture below.






























domingo, 12 de abril de 2015

I2C

This practice is intended by the LCD visualize date, time, temperature. The data for the date obtained by the DS1307 device which has a battery and a much more accurate oscillator which has the ATMEGA 328P. This device has a memory NVRAM 56bytes.
On the other hand we have another device to take the temperature called DS1621, which takes us to the room temperature (changeable with arrows).
The aim is to understand the connection protocol I2C which is used by the ATMEGA328P to interact with the devices described above.
Having achieved this, the tutor urges us to keep the program within the first minute in a part of the memory of the DS1307 data on temperature and date. Then follow showing the time until the second minute which will be stored the same data as before but obviously outdated one minute (which
is what happened time). As addition has placed a button that wakes the ATMEGA328P to not let frezee.
To end the tutor ordered it done physically, ie in reality, for this we have the above items.
To give a twist, wants to load up the program through a device called a programmer in this case is the ATMEL AVR. Once the process is finished loading addition to checking for correct operation, wants to load up the bootloader with the developer this is due to loading the program eliminated the bootloader and we could not load more programs through the IDE USB (standard practice).
First we make the circuit as shown in the following image.
image 
Returning to explain in brief the method to follow and operation of the SPI protocol and how to save data in memory.
This practice is to date the LCD visualize, time, temperature. To do this we will read through the I2C protocol to watch and temperature sensor. Save NVRAM this data at intervals of one minute each and sleeping ATMEGA328P.
When we look NVRAM DS1307 will have some data, the first are second followed by minutes time, day of the week (1 being Sunday), day, month, year, followed by 00 (SQWE control)and starts at 08H NVRAM that will keep the data as we have indicated by code below.
We also have the I2C debugger in proteus that helps us visualize the Protocol were communication,begins with a start bit or start of the transmission, followed by a control code of 4 bits here are three bit of your host device Seleción another bit read or write and a recognition and for transmission. This would only be for communication, if the slave responds as appropriate.
Repetitive use another start control the choice of dispositvo, read or write, and stop transmission acknowledgment.
Then we explain the Sketch.
image 
Include the libraries.
image 


Statement of objects and variables.
image 
We started the elements and determine the size of 16x2 LCD.
image
Top 0x48 broadcast address , access settings sensor , determining that the output is active high and continuous conversion , ending transmission. Once activated starts the protocol to start converting transmission and transmission ends. 
image
But have the time set by the RTC gets the computer.
image 
Initializes everything to be prepared disruption , interruption Three types have chosen this , and must be present when you ordered do it. We also put a 1 pin2 for interrupting , when we have it 0 out of interruption. Finalizing have a function that is what we want to do in disruption in this case goes to the event function is an empty function that does not return anything.
image 
We write the start date of the RTC clock in memory print the serial nvram.Después day, month , year and in the next line the hour, minutes and seconds everything in decimal.Seguidamente begin transmission with temperature sensor , started with 0xAA command to read the sensor, completed the transmission. We tell the direction and bytes occupied in this case 1. Then we say that tempC equals reading Wire , print the word serial temperature followed by the value of tempC and a character C.
image
We clean what's on the LCD , we say we will go to the 3-position of the first row, the LCD and print the current day , followed by the month and year . In the second row that is to position 1 and print the hour, minute, second current and temperature.
image
Now we are going to save the data from 1 to 2 minutes in NVRAM. For 1 minute, start with a consistent variables in timer in periods of 1 second. If the counter reaches 60 seconds , writes the data to a whole array elements 7 an unsigned byte . The write in position 0 , 7 data. Furthermore we print a warning by the serial to know that you have saved . The same procedure for 2 minutes we give us time to save the data correctly and slept the micro. If you press the button that we have put our micro wakes.
image
Function we want to do when interrupted , in this case we do not want to do anything or return anything.
Now a video of practice run in proteus.

To download the files from all the practice you must click on the picture below.

 

Web server

With this practice the aim is to make a web server with Arduino, with a mandate to give data from a temperature sensor.
With this system we can check the status of temperature of a place through internet.
This requires having an Arduino Uno, an Ethernet shield, and a temperature sensor LM35.
The connection is simple we connect the Arduino with the shield , also free analog pins will have to enter the temperature sensor.
The chosen temperature sensor is LM35 which is built into the shield of MSE.
image 
As a shield for the given pin is the analog sensor 4 or A4 , as shown in Sketch.


Therefore the assembly and would be shown in the image.
clip_image001
Down the Arduino Uno is observed over the Ethernet shield , and followed it should go the MSE, being a shield of Integrated Center, and more expensive, you can choose from that I put in the picture is the DS18B20.
clip_image002
The difference is that the former does not need library, and second whether the Texas Instuments to operate by the SPI protocol.
Once compound system , now it's shaping our router , so we must go to "MS -DOS " introduce cmd in the search box win8 or XP Run.
We introduce ipconfig / all for our address of the router to configure it.
clip_image003
In the area where it says default gateway , see the direction that most often 192.168.1.1 but would have to look at each router.
We enter this address in the browser and configure the router.
clip_image004
We introduce the username and password we provided by the manufacturer or supplier.
Once inside we have to look ports, or open ports in my case is in the tab Firewall / Redir Port.
clip_image005
Once inside we add one , in this case we will open the 8081, and we will give a fixed IP is 192.168.1.120
clip_image006
And it is added in this case in my router so.
clip_image007
Well once seen the procedure , we go to Sketch.
clip_image008
We include the SPI and Ethernet libraries are for the Ethernet shield work.
MAC determine the shield , but it must be on the back thereof.
The IP address to determine the router.
We open the port on the router.
the pin where our sensor is connected and the variables for proper operation.
clip_image009
Start the server and print the serial IP .
The Sketch is observed as a connection and html server protocol and is performed.
It is also observed as the conditioning performed if more than 25 ° or is lower than display.
clip_image010clip_image011clip_image012
Sketch Once loaded, we go to the browser and enter our shocket (address port) 192.168.1.120:8081 and this image is observed.
clip_image013
clip_image014

To download the files from all the practice you must click on the picture below.


































martes, 10 de marzo de 2015

Practice SPI


Then SPI practice occurs. We have a ATMEGA328P microcontroller that is on the Arduino board that controls the process.
Through the SPI protocol I entered values ​​that are in the code you what is displayed in the Source Code tab.
The practice is to send values ​​to a slave who has 6 potentiometers the name of this device is AD5206BN10. The protocol used for the communication is SPI.
Captura1
Communication is observed on the monitor of SPI's like going the whole process starts with the micro bootloader to start work, once completed this boot begins to execute the instructions contained in the code. Instructions ranging from master to slave codes are 8 bits in the last three are for the direction of the potentiometer and the other 8 is to put the potentiometer value from 0 to 255. The transfer starts with falling edge to select the potentiometer SS and clock signals going through the MOSI sending 8 bits.
Captura2
In the SPI debugger see how choose the potentiometer and then sends the data. The control to choose the potentiometer will be 0 0 0 0 0 0 0 0 0 0, 1, 0 0 1 ...... and so do 6 potentiometers. In this case the master does not hear the slave because it has MISO therefore continue to send information to be proven. After this information, it will send the same way a command whose control code is the value we want to take the Ohm-meter followed potentiometer byte size we want for example the number 216 and we displayed in hexadecimal as D8.
Captura3
After pressing the PLAY button located at the bottom of the screen, it will run once and ending with the entered values, which start from an increased 1.5K 1.5K potentiometer, ie the potentiometer 1 display a value of 1.5K, 3K 2nd and so on with the 6 potentiometers.
I placed an intermediate SPI instrument that shows what is going on while the program is running.
This tool helps us when we perform breakpoints and have a detailed process information.
The 6 potentiometers are inside the integrated AD5206BN10, it has some entries which are CLK, SDI and CS.
The CLK input is for the SCK is the clock for the slave.
The teacher sends clock pulses to receive the slave with pulses of orders should receive.
The SDI is the input that has a slave to hear the teacher.
The CS input in this case is denied because you choose active low, if we had more integrated or other device with the same protocol through this pin the teacher chooses who send an order.

To download the files from all the practice you must click on the picture below.