Commit 126e01b0 authored by Martin Enriquez's avatar Martin Enriquez

Armados proyectos a mano para manejar solo codigo

parents 3c8eca97 246519dd
# Reglas para ignorar archivos de Eclipse
.metadata/
RemoteSystemsTempFiles/
.settings/
# Reglas para ignorar compilaciones
Debug/
Release/
.project
.cproject
# Otras reglas
Rasp Pi VNC
copyrightLog.txt/
# Proyecto de Domótica | Técnicas Digitales III - UTN FRA
# Proyecto de Domótica
### Martín Enríquez - Leandro Lanzieri
#### Proyecto realizado para la cátedra de Técnicas Digitales III - UTN FRA
## Objetivo Principal
Se pretende armar un sistema de control automatizado y reprogramable para hogares, de bajo costo, inalámbrico y accesible de manera remota a través de Internet. La idea es poder establecer una red formada por nodos sensores y actuadores que reporten a uno central donde se toman decisiones en consecuencia. El nodo central también es responsable de interactuar con el usuario de manera local y a través de Internet en caso de poseer conexión.
[Más información en la Wiki](https://gitlab.com/leandrolanzieri/proyecto-digitales/wikis/home)
\ No newline at end of file
[Más información en la Wiki](https://gitlab.com/leandrolanzieri/proyecto-digitales/wikis/home)
===
Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
El proyecto esta distribuido bajo la licencia [GNU GPLv3](http://www.gnu.org/licenses/gpl-3.0.en.html).
\ No newline at end of file
<?xml version="1.0"?>
<XLaunch xmlns="http://www.straightrunning.com/XmingNotes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.straightrunning.com/XmingNotes XLaunch.xsd" WindowMode="Windowed" ClientMode="StartProgram" Program="startlxde" ClientStart="PuTTY" PasswordStart="true" RemoteHost="192.168.137.2" RemoteUser="pi" Display="1" Clipboard="true"/>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Remoto-con-8</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Modulo_Luces</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Modulo_On_Off</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>de.innot.avreclipse.core.avrnature</nature>
</natures>
</projectDescription>
Old copyright not at start of file, new copyright replaces old in same location
/prueba-adc/configuracion.h
/prueba-adc/hardware.h
/prueba-adc/main.c
/prueba-adc/mcu.c
/prueba-adc/mcu.h
Failed to create internal source file for proccessing the file
/prueba-adc/.cproject
/prueba-adc/.project
/prueba-adc/.settings/de.innot.avreclipse.core.prefs
/*
* Proyecto Domotica | Nodo Central
* comunicacion.h
* Contiene los comandos que son interpretables por todos los nodos
* de la red. Tambien las frecuencias predefinidas para cada tipo
* de nodo.
*/
/*******************************************************************************
* Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
*
* This file is part of Proyecto Domotica.
*
* Proyecto Domotica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proyecto Domotica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proyecto Domotica. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#ifndef COMUNICACION_H_
#define COMUNICACION_H_
/* ======== COMANDOS ========= */
#define RELE_ON 0x0F
#define RELE_OFF 0x01
#define RELE_TOGGLE 0xDA
#define ENTRO_PANTALLA 0x07
#define LUCES_ON 0x1F
#define LUCES_OFF 0x11
#define LUCES_TOGGLE 0x1A
#define LUCES_DUTY 0x1D
#define LUCES_AUMENTAR 0x1B
#define LUCES_DISMINUIR 0x1C
/* ======= FRECUENCIAS ======== */
#define FREC_LUCES 0x66
#define FREC_ON_OFF 0x78
#endif /* COMUNICACION_H_ */
/* Proyecto Domotica | Nodo Central
* configuracion.h
* Importa las librerias propias de AVR. Define constantes de configuracion del funcionamiento
* general del programa, como la frecuencia del cristal utilizado y el baud rate para la
* comunicacion serial.
*/
/*******************************************************************************
* Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
*
* This file is part of Proyecto Domotica.
*
* Proyecto Domotica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proyecto Domotica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proyecto Domotica. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#ifndef CONFIGURACION_H_
#define CONFIGURACION_H_
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <string.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define FOSC 8000000 // 8MHz Frecuencia de oscilacion
/* UART */
#define BAUD 9600 // Baud Rate
#define UBRRREG ((FOSC/16)/BAUD)-1 // El reultado debe ser el numero del registro UBRR para tener BAUD
/* NRF24L01 */
#define dataLen 5 // Tamao de la carga til (payload) - 1 a 32 bytes
#endif /* CONFIGURACION_H_ */
/*
* Proyecto Domotica | Nodo Central
* hardware.h
* Contiene las definiciones de pines, puertos y registros que son propios de
* cada placa. Tambien una escructura de manejo de a bits.
*
*/
/*******************************************************************************
* Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
*
* This file is part of Proyecto Domotica.
*
* Proyecto Domotica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proyecto Domotica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proyecto Domotica. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#ifndef HARDWARE_H_
#define HARDWARE_H_
/**************************************Definiciones para Manejo de a bit**********************************/
typedef struct
{
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
}BIT;
#define REGBIT(reg,bt) ((volatile BIT*)&reg)->B##bt //MACRO PARA MANEJAR REGISTROS DE A BIT.
/*********************************************************************************************************/
/* Led onboard */
#define LED_PORT PORTD
#define LED_PIN 7
#define LED_DDR DDRD
#define LED REGBIT(PORTD, 7)
/* Chip Enable del NRF24L01 */
#define CE_PORT PORTB
#define CE_PIN 1
#define CE_DDR DDRB
#define CE REGBIT(PORTB, 1)
/* Chip Select Not del NRF24L01 */
#define CSN_PORT PORTB
#define CSN_PIN 2
#define CSN_DDR DDRB
#define CSN REGBIT(PORTB, 2)
/* SPI MOSI */
#define MOSI_PORT PORTB
#define MOSI_PIN 3
#define MOSI_DDR DDRB
#define MOSI REGBIT(PORTB, 3)
/* SPI MISO */
#define MISO_PORT PORTB
#define MISO_PIN 4
#define MISO_DDR DDRB
#define MISO REGBIT(PORTB, 4)
/* SPI SCK */
#define SCK_PORT PORTB
#define SCK_PIN 5
#define SCK_DDR DDRB
#define SCK REGBIT(PORTB, 5)
/* Interrupciones Externas Int0 */
#define INT0_PORT PORTD
#define INT0_PIN 2
#define INT0_DDR DDRD
#endif /* HARDWARE_H_ */
/*
* Proyecto Domotica | Nodo Central
* main.c
* El nodo central debe poder comunicarse a traves de la UART para poder
* enviar y recibir comandos e informacion desde el control central del
* sistema de domotica.
*
* Tambien debe establecer una conexion de tipo estrella con los demas
* nodos para enviar y recibir comandos e informacion. La conexion con
* los nodos es inalambrica y se realiza utilizando el modulo NRF24L01+,
* a traves de SPI.
*/
/*******************************************************************************
* Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
*
* This file is part of Proyecto Domotica.
*
* Proyecto Domotica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proyecto Domotica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proyecto Domotica. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "configuracion.h"
#include "comunicacion.h"
#include "hardware.h"
#include "uart.h"
#include "mcu.h"
#include "nrf24l01.h"
int main(void) {
unsigned char datos[5];
inicializarTodo();
Modo_TX(); // Cambia a transmitir
Set_frec(FREC_ON_OFF);
ledBlink();
datos[0] = RELE_TOGGLE;
datos[1] = RELE_TOGGLE;
datos[2] = RELE_TOGGLE;
datos[3] = RELE_TOGGLE;
datos[4] = RELE_TOGGLE;
while(1) {
_delay_ms(1000);
transmit_payload(datos); // Envia los datos
/* NOTA: Este delay y reset hacen la comunicacion estable, si no estan
* se produce una falla permanente o perdida de datos. Se evaluara colocarlos
* dentro de la funcion de envio de paquetes.
*/
_delay_ms(20);
reset();
LED ^= 1; // Led toggle
}
}
/*
* Proyecto Domotica | Nodo Central
* mcu.c
* Contiene las funciones generales que se usan en el programa. En este caso de incializacion,
* uso de UART y encendido del led onboard.
*/
/*******************************************************************************
* Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
*
* This file is part of Proyecto Domotica.
*
* Proyecto Domotica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proyecto Domotica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proyecto Domotica. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "configuracion.h"
#include "uart.h"
#include "mcu.h"
#include "hardware.h"
void inicializarTodo() {
inicializarUART();
inicializarGPIO();
inicializarSPI();
// inicializarInterrupcionesExternas();
inicializarNRF24L01();
sei(); // Habilita interrupciones
}
void inicializarGPIO(void) {
/* Led onboard */
LED_DDR |= (1 << LED_PIN); // Led como salida
LED = 1; // Se enciende con 0
}
void inicializarSPI(void) {
/* Pines de comunicacion con NRF24L01 */
SCK_DDR |= (1 << SCK_PIN); // SPI SCK como salida
MOSI_DDR |= (1 << MOSI_PIN); // SPI MOSI como salida
CE_DDR |= (1 << CE_PIN); // CE como salida
CSN_DDR |= (1 << CSN_PIN); // CSN como salida
/* Habilita comunicacion SPI y se configura al microcontrolador como master */
SPCR |= (1 << SPE) | (1 << MSTR) | (1 << SPR0);
CE = 1;
CSN =1;
}
void inicializarInterrupcionesExternas(void) {
INT0_DDR &= ~(1 << INT0_PIN); // INT0 como entrada
MCUCR |= (1 << ISC01); // INT0 detecta flanco descendente
GICR |= (1 << INT0); // Habilito la interrupcion de INT0
}
/* Misc */
void ledBlink(void) {
char i;
for(i=0; i<6; i++) {
LED ^= 1; //Toggle Led
_delay_ms(155);
}
}
/*
* Proyecto Domotica | Nodo Central
* mcu.h
* Contiene los prototipos de las funciones de mcu.c
*/
/*******************************************************************************
* Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
*
* This file is part of Proyecto Domotica.
*
* Proyecto Domotica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proyecto Domotica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proyecto Domotica. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#ifndef MCU_H_
#define MCU_H_
/* Funciones de Inicializacion */
void inicializarTodo(void);
void inicializarGPIO(void);
void inicializarInterrupcionesExternas(void);
void inicializarSPI(void);
void inicializarNRF24L01(void);
/* Misc */
void ledBlink(void);
#endif /* MCU_H_ */
/*
* Proyecto Domotica | Nodo Central
* nrf24l01.c
* Contiene las funciones para comunicarse utilizando el modulo
* NRF24L01+ a traves de SPI. Tambien funciones utilies para su
* uso y configuracion.
*/
/*******************************************************************************
* Copyright (c) 2015 Martin Enriquez, Leandro Lanzieri Rodriguez
*
* This file is part of Proyecto Domotica.
*
* Proyecto Domotica is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Proyecto Domotica is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Proyecto Domotica. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
#include "configuracion.h"
#include "comunicacion.h"
#include "nrf24l01.h"
#include "hardware.h"
char WriteByteSPI(unsigned char cData)
{
SPDR = cData;
while(!(SPSR & (1<<SPIF)));
return SPDR;
}
void PCINT12_interrupt_init(void)
{
DDRD &= ~(1 << DDD2); // INT0 (PD2)como entrada
MCUCR |= (1 << ISC01); // INT0 en falling edge
MCUCR &= ~(1 << ISC00);
MCUCR &= ~(1 << ISC10); // INT0 en falling edge
GICR |= (1 << INT0); //Habilito la interrupci�n
}
uint8_t GetReg(uint8_t reg) //Funci�n para leer un registro reg
{
_delay_us(10);
CSN = 0;
_delay_us(10);
WriteByteSPI(R_REGISTER + reg);
_delay_us(10);
reg = WriteByteSPI(NOP);
_delay_us(10);
CSN = 1;
return reg;
}
uint8_t *WriteToNrf(uint8_t ReadWrite, uint8_t reg, uint8_t *val, uint8_t antVal) //Funci�n de lectura o escritura
//"W o R" (Escribir o leer), "reg" (el registro), "*val" (valor a escribir) & "antVal" (cantidad de enteros a escribir)
{
cli();
if (ReadWrite == W)
{
reg = W_REGISTER + reg;
}
static uint8_t ret[dataLen];
_delay_us(10);
CSN = 0;
_delay_us(10);
WriteByteSPI(reg);
_delay_us(10);
int i;
for(i=0; i<antVal; i++)
{
if (ReadWrite == R && reg != W_TX_PAYLOAD)
{
ret[i]=WriteByteSPI(NOP);
_delay_us(10);
}
else
{
WriteByteSPI(val[i]);
_delay_us(10);
}
}
CSN = 1;
sei();
return ret;
}
void inicializarNRF24L01(void)
{
//_delay_ms(100);
uint8_t val[5];
val[0]=0x03;
WriteToNrf(W, EN_AA, val, 1); //Habilito auto ACK en P0
val[0]=0x2F;
WriteToNrf(W, SETUP_RETR, val, 1); //Configuro la retransmisi�n con un ARD=705useg y ARC=15
val[0]=0x03;
WriteToNrf(W, EN_RXADDR, val, 1); //Habilito el P0
val[0]=0x03;
WriteToNrf(W, SETUP_AW, val, 1); //Seteo 5 bytes de longitud de direcci�n
val[0]=FREC_ON_OFF;
WriteToNrf(W, RF_CH, val, 1); //Seteo el canal de frecuencia 2,502 GHz
val[0]=0x26;
WriteToNrf(W, RF_SETUP, val, 1); //Seteo vel de transmisi�n en 250Kb/s y potencia en 0dBm
int i;
for(i=0; i<5; i++)
{
val[i]=0x12; //N�mero de direcci�n
}
WriteToNrf(W, RX_ADDR_P0, val, 5); //Cargo la direcci�n del RX
for(i=0; i<5; i++)
{
val[i]=0x13; //N�mero de direcci�n
}
WriteToNrf(W, RX_ADDR_P1, val, 5); //Cargo la direcci�n del RX
for(i=0; i<5; i++)
{
val[i]=0x12; //N�mero de direcci�n
}
WriteToNrf(W, TX_ADDR, val, 5); //Cargo la direcci�n del TX
// Configuraci�n de capacidad de la carga �til (payload) - Est�tica de 1 - 32 bytes
val[0]=dataLen;
WriteToNrf(W, RX_PW_P0, val, 1);
val[0]=dataLen;
WriteToNrf(W, RX_PW_P1, val, 1);
val[0]=0x7E; //Configuraci�n de modo, TX=7E - RX=1F
WriteToNrf(W, CONFIG, val, 1);
//_delay_ms(100);
}
void reset(void)
{
_delay_us(10);
CSN = 0;
_delay_us(10);
WriteByteSPI(W_REGISTER + STATUS);
_delay_us(10);
WriteByteSPI(0b01110000);
_delay_us(10);
CSN = 1;
}
void receive_payload(void)
{
sei();
CE = 1;
_delay_ms(1000);
CE = 0;
cli();
}
void transmit_payload(uint8_t * W_buff)
{
WriteToNrf(R, FLUSH_TX, W_buff, 0);
WriteToNrf(R, W_TX_PAYLOAD, W_buff, dataLen);
sei();
_delay_ms(10);
CE = 1;
_delay_ms(1);
CE = 0;
_delay_ms(10);
}
void Modo_TX(void)
{
uint8_t val[5];
val[0]=0x7E; //Configuraci�n de modo, TX=7E - RX=1F
WriteToNrf(W, CONFIG, val, 1);
CE=0;
}
void Modo_RX(void)
{
uint8_t val[5];
val[0]=0x1F; //Configuraci�n de modo, TX=7E - RX=1F
WriteToNrf(W, CONFIG, val, 1);
}
void Set_frec(uint8_t frecuencia)
{
uint8_t val[5];
val[0]= frecuencia;