Fikret
Published

Omega2 Software Development Board

Omega2 is small and powerful Linux board. But it has few GPIO. I prepared dedicated MCU and RF chip to collect data for it.

AdvancedWork in progressOver 4 days938
Omega2 Software Development Board

Things used in this project

Hardware components

Omega2 Plus
Onion Corporation Omega2 Plus
×1
Texas Instruments tps5410
×1
HMTRP
HMTRP rf chip by HOPE RF
×1
Microchip Pic24fj256gb106
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1

Software apps and online services

OPENWRT Linux
Python
CCS C Programming Lang.

Story

Read more

Custom parts and enclosures

Omega2 Xbee Board

Omega2 Xbee Board

Relay Board

Relay Board

Xbee Shield Board

SMPS Board

SMPS Board

Schematics

Proteus ARES Design

Omega2+ development, Xbee Shield, DS1307, 24C eeprom, Ethernet, USB, Wifi, +16GPIO with peripherals

Controls 4 relays, 4 ch open collector output and 4 ch Opto input

Code

Omega2 Python File

Python
Omega2+ python File
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#Bismillahirrahmanirrahim
from time import sleep
import onionGpio
import serial
import sqlite3 as db
import os


# define pins
pinLed0=16		# GPIO Led
pinLed1=17		# GPIO Led
pinLed2=18		# GPIO Led
pinLed3=19		# GPIO Led

pinMcuInp=11

# define states
ON=1
OFF=0
line=""

tryOut=30
sayac=0

# tanımlar
dbFile="/home/py/xbee/db/db.sqlite"

# saat ve tarih tanımları
sa=0
dk=0
sn=0

gun=0
ay=0
yil=0

dkEx=0
saEx=0

gunEx=0
ayEx=0

dummyText=""
komut=""


# pin tanımlama ve konfigürasyonu
led0= onionGpio.OnionGpio(pinLed0)
led1= onionGpio.OnionGpio(pinLed1)
led2= onionGpio.OnionGpio(pinLed2)
led3= onionGpio.OnionGpio(pinLed3)

mcuInp=onionGpio.OnionGpio(pinMcuInp)


# pin direction
led0.setOutputDirection(ON)
led1.setOutputDirection(ON)
led2.setOutputDirection(ON)
led3.setOutputDirection(ON)

mcuInp.setInputDirection() #gsm module açık kapalı bildirimi için giriş olarak ayarlandı

led0.setValue(ON)
led1.setValue(OFF)
led2.setValue(OFF)
led3.setValue(OFF)


#fonksiyonlar

def dbKontrol():
	dosyaMevcut=os.path.exists(dbFile)
	if not dosyaMevcut:
		dbOlustur()
	else:
		print("db dosyası var.\r\n")
		
def dbOlustur():
	vt=db.connect(dbFile)
	im=vt.cursor()
	#im.execute("CREATE TABLE arac(id,plate,marka,model,yas,barcode)")
	#vt.commit()
	im.execute("""
	CREATE TABLE action(
	'id' INTEGER PRIMARY KEY AUTOINCREMENT,
	'longitude' VARCHAR(25),
	'longitudeDir'  VARCHAR(5),
	'latitude' VARCHAR(25), 
	'latitudeDir' VARCHAR(5), 
	'rakim'  REAL,
	'yon' REAL,
	'kms' REAL,
	'knot' REAL,	
	'tarih' VARCHAR(10), 
	'saat' VARCHAR(10)
	)""")
	#im.execute("CREATE TABLE action(id,enlem,boylam,rakim,yon,hiz,tarih,saat)")
	vt.commit()
	vt.close()
	print("Veritabanı olusturuldu\r\n")

def veriGir(longitude,longitudeDir,latitude,latitudeDir,rakim,yon,kms,knot,gsmTarih,gsmSaat):
	with db.connect(dbFile) as vt:
		im=vt.cursor()
		sorguText="""INSERT INTO 
		action(longitude,longitudeDir,latitude,latitudeDir,rakim,yon,kms,knot,tarih,saat) 
		values('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}') """.format(longitude,longitudeDir,latitude,latitudeDir,rakim,yon,kms,knot,gsmTarih,gsmSaat)
		#print (sorguText)
		im.execute(sorguText)
		vt.commit()
		print("Veritabanına eklendi")	
# bütün seri port yazma işini ve porttan okuma işini bir rutine bağla.
# böylece SMS bildirimlerini burada kaçırmadan kontrol edebilirsin.

def seriPortYaz(veri,bekle=1,bildir=""):
	ser.write(veri.encode('utf-8'))
	sayac=0
	while(ser.in_waiting==0) and  (sayac<bekle):
		sleep(0.1)
		sayac+=1
	if bildir!="":
		print("SER: {}\r\n".format(bildir))
	gsmRespText=ser.read(ser.in_waiting)
	print("Ser Read: {}\r\n".format(gsmRespText))
	
	return gsmRespText
	#if "+CMTI:" in gsmRespText:
	#	smsSorgula()
#def smsSorgula():
#-----------------başlıyoruz ------------------
dbKontrol() #veritabanı var kontrol et yoksa oluştur varsa aşağıda bağlan
# terminal seri portu 
terminal=serial.Serial()
terminal.baudrate=115200
terminal.port='/dev/ttyS0'
terminal.open()

#sm modül iletişim seri portu
ser=serial.Serial()
ser.baudrate=115200
ser.port='/dev/ttyS1'
ser.open()
sleep(0.1)
sayac=0



while(True):
	if(sayac%10==0):
		print("sayac: {}\r\n".format(sayac))
	sayac+=1
	if terminal.in_waiting>0:
		terminalRespText=terminal.read(terminal.in_waiting).decode('utf-8')
		if "q" in terminalRespText:
			break

	#led.setValue(OFF)
	
	if ser.in_waiting>2:	# eğer veri varsa al ve değerlendir.
		#seriporttan veri gelirken kesme oluşmadığı için bekleme yaparak 
		#veri alınıyor. Bu bekleme esnasında da bazen veri alınırken veri 
		#ortada kesilebiliyor
		#bunun için küçük bir bekleme test rutini ekledim.
		bekleyen=ser.in_waiting
		sleep(0.1)
		if ser.in_waiting != bekleyen:
			sleep(0.2)
		serData=ser.read(ser.in_waiting).decode('utf-8')
		print("Veri: {}".format(serData))
		print("------------------------\r\n")
		
		#veri gelince rutin olarak cevap yaz
		komut="sayac={}\r".format(sayac)		# SMS göndermek için başla
		ser.write(komut.encode('utf-8'))



	sleep(0.1)
	
ser.close()

PIC Main.c

C/C++
PIC Mcu main rutine
#include <main.h>

#include <def.h>
#include <regs.h>
#include <2465x.c>
#include <ds_1307.c>
//#include <ds18b20.c>
#include <func.c>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#int_CNI
void CCNI_Interrupt()
{
   if (input(sw1)==0)
      {
         fprintf(dbg,"sw1 press\r\n");
         bekle(tOrta);
      }
      if (input(sw2)==0)
      {
         fprintf(dbg,"sw2 press\r\n");
         bekle(tOrta);
      }
      if (input(sw3)==0)
      {
         fprintf(dbg,"sw3 press\r\n");
         bekle(tOrta);
      }
      if (input(sw4)==0)
      {
         fprintf(dbg,"sw4 press\r\n");
         bekle(tOrta);
      }
  
}

#INT_EXT0
void  ext0_isr(void) 
{

}

#INT_EXT1
void  ext1_isr(void) 
{

}

//omega2 communication
#INT_RDA
void  rda_isr(void) 
{
   intRdaState=1;
   hiX(ledIntRda);
   rdaDataCounter=0;
   rdaTempCounter=0;
   
   while(rdaTempCounter<10000)
   {
   
      rdaTempCounter++;
      if (kbhit(omega))
      {
         chr=fgetc(omega);
         if(chr>32)
         {
            rdaData[rdaDataCounter]=chr;
            rdaDataCounter++;
            rdaTempCounter=0;
         }
      }      
   
   }
   
   rdaData[rdaDataCounter]=0;
   
   
   lox(ledIntRda);

}
//debug communication
#INT_RDA2
void  rda2_isr(void) 
{

   intRda2State=1;
   hiX(ledIntRda);
   rda2DataCounter=0;
   rda2TempCounter=0;
   
   while(rda2TempCounter<10000)
   {
   
      rda2TempCounter++;
      if (kbhit(dbg))
      {
         chr=fgetc(dbg);
         if(chr>32)
         {
            rda2Data[rda2DataCounter]=chr;
            rda2DataCounter++;
            rda2TempCounter=0;
         }
      }      
   
   }
   
   rda2Data[rda2DataCounter]=0;
   
   
   lox(ledIntRda);



}
//XBee sgield communication
#INT_RDA3
void  rda3_isr(void) 
{

}

#INT_RDA4
void  rda4_isr(void) 
{

}



void main()
{

 
   //setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 999);
   //setup_timer5(TMR_INTERNAL | TMR_DIV_BY_1, 999);

   //setup_adc_ports(sAN0 | sAN1 | sAN2 | sAN3 | sAN4 | sAN5 | sAN6, VSS_VDD);
   //setup_adc(ADC_CLOCK_DIV_16 | ADC_TAD_MUL_0);

   //setup_compare(1, COMPARE_PWM_EDGE | COMPARE_TIMER5 | COMPARE_SYNCHRONIZE | COMPARE_TRIG_SYNC_NONE);
   //set_pwm_duty(1, 32768);
   //setup_compare(2, COMPARE_PWM_CENTER | COMPARE_TIMER4 | COMPARE_SYNCHRONIZE | COMPARE_TRIG_SYNC_NONE);
   //set_compare_time(2, 16384, 49152);

   enable_interrupts(INTR_CN_PIN |sw1);
   enable_interrupts(INTR_CN_PIN |sw2);
   enable_interrupts(INTR_CN_PIN |sw3);
   enable_interrupts(INTR_CN_PIN |sw4);
   
   init_ext_eeprom();
   bekle(tkisa);
   ds1307_init(); // saat init
   bekle(tkisa);
   
    //saat ayarlama kısmı
   
   //ds1307_set_time(20,40,30);                      //Saat ayarla
   bekle(tKisa);
   //ds1307_set_date(12,1,19,6);                     //Tarih ayarla dow değeri önemli olmasa da ayrla belki ilerde kullanılır.
   bekle(tKisa);
   
   /*
   ds1307_get_time(myClock.hrs,myClock.min,myClock.sec);
   ds1307_get_date(myClock.day,myClock.month,myClock.year,myClock.dow);
       
   
   fprintf(dbg," Saat: %u:%u:%u Tarih:  %u:%u:%u\r\n"myClock.hrs,myClock.min,myClock.sec,myClock.day,myClock.month,myClock.year);
   */
  

   digOut(rfEnable);
   digOut(rfConf);
   digOut(iAmAlive);
   digOut(ledIntRda);
   digOut(ledIntRda2);
   digOut(ledIntRda3);
   digOut(ledIntCN);
   
   digOut(rl1);
   digOut(rl2);
   digOut(rl3);
   digOut(rl4);
   
   
   digOut(openCol1);
   digOut(openCol2);
   digOut(openCol3);
   digOut(openCol4);

   
   digIn(sw1);
   digIn(sw2);
   digIn(sw3);
   digIn(sw4);
   
   hmtrp(enable); 
   bekle(tSn);
   
   //enable_interrupts(INT_EXT0);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_CNI);
   //enable_interrupts(INT_EXT1);
   enable_interrupts(INT_RDA2);
   //enable_interrupts(INT_RDA3);
   //enable_interrupts(INT_RDA4);
   enable_interrupts(INTR_GLOBAL);
   fprintf(dbg,"FiDeNet \r\n");
   fprintf(omega,"FiDeNet Omega\r\n");
   fprintf(rf,"FiDeNet rf\r\n");
    /* 
   
   //relay test
   hiX(rl1);
   bekle(tSn);
   hiX(rl2);
   bekle(tSn);
   hiX(rl3);
   loX(rl1);
   bekle(tSn);
   hiX(rl4);
   loX(rl2);
   bekle(tSn);
   loX(rl3);
   bekle(tSn);
   loX(rl4);
   */
   eepromRdTest();
   eepromWrTest();
   
   processPlanner=0;
   while(TRUE)
   {
      enable_interrupts(INT_RDA2);
      //TODO: User Code
      bekle(tMicro);
      processPlanner++;
      if (processPlanner%1000==0)
      {
         fprintf(omega,"FiDeNet Omega Test\r\n");
      
      }
      if (processPlanner%200==0)
      {
         hiX(iAmAlive);
      }
      if (processPlanner%200==100)
      {
         loX(iAmAlive);
      }
      //omega uart portuna veri gelince 
      if (intRdaState==1)
      {
         fprintf(dbg,"rdaData:%s\r\n"rdaData);
         intRdaState=0;
      }
      //debug uart portuna veri gelince 
      if (intRda2State==1)
      {
         fprintf(dbg,"rda2Data:%s\r\n"rda2Data);
         intRda2State=0;
      }
   }

}

PIC Mcu regs rutine

C/C++
Pic Mcu Regs Rutine
/*Cihaz ile ilgili kullanılacak sabitler*/
enum sabitler{
      cHWID,
      cSWVersion,
      cHwR,
      mfc,  //manifacturer
   };
   
   typedef struct hw_strings{
      u8 sbt;
      char str[20];

   }myHwStrings;
   
   
  myHwStrings const deviceData[10]={
      cHWID,{"FD.RAL.MCU.R03"},
      cSWVersion,{"1.0.0"},
      cHwR,{"1.0.1"},
      mfc,{"FiDeNet UKoSis"},
   };
   
   enum enumCommands{
      cAT,
      cATHwID,
      cATSw,
      cATHwR,
      cATMfc,  //manifacturer
      cATID,
      cATIDW,
      cATIDC,
     
      
   };
   
   typedef struct strctCommandText{
      u8 sbt;
      char str[20];

   }myHwCommands;
   
   
  myHwCommands const MyCommands[15]={
      cAT,{"AT\r"},
      cATHwID,{"ATHwID\r"},
      cATSw,{"ATSw\r"},
      cATHwR,{"ATHwR\r"},
      cATMfc,{"ATMfc\r"},
      cATID,{"ATID\r"},
      cATIDW,{"ATIDW="},
      cATIDC,{"ATIDC\r"},
     
   };
   

u16 counterGen;        //genel sayaç
u8 resp;

u16 processPlanner;

u8 readDevIDOk=0;
u8 devIDAddr=10;
char devID[30];


//rda rutini değişkenleri   
   
   
char tempBuffer[30];   // id yazma için kullanılan ara değişken

char chr;
//char rdaBuffer[100];
//char rda2Buffer[100];

u16 rdaTempcounter;
u16 rda2Tempcounter;
u16 rda3Tempcounter;


u8 rdaDataCounter;
u8 rda2DataCounter;



u1 intRdaState=0;
u1 intRda2State=0;
u1 intRda3State=0;


u1 intExtState=0;
u1 intExt1State=0;


char rdaData[100];
char rda2Data[100];
char rda3Data[100];




char strGen1[10];
u16 genCounter;
u8 genCounter2;

//GSM commands and regs

u1 gsmPowerState;
u1 intExtFirst=1;
u8 ringCount;
u16 ringTempCounter;
u8 ringCountMax=2;
u16 diff;


typedef struct timeDef{
   u8 sec; 
   u8 min; 
   u8 hrs; 
   u8 day; 
   u8 month; 
   u8 year; 
   u8 dow;
   u8 temp;
   u16 id;
}myTimeDefs;

myTimeDefs myClock;

PIC Mcu definitions

C/C++
PIC Mcu definitions
typedef  int1 u1;
typedef  unsigned int8 u8;
typedef  volatile unsigned int8 vu8;
typedef  unsigned int16 u16;
typedef  volatile unsigned int16 vu16;
typedef  unsigned int32 u32;


#define bekle(x) delay_ms(x)
#define digOut(x) output_drive(x)
#define digIn(x) output_float(x)


#pin_select U1TX=PIN_D1
#pin_select U1RX=PIN_D2
#use rs232(UART1, baud=115200, stream=omega)

#pin_select U2TX=PIN_B5
#pin_select U2RX=PIN_B4
#use rs232(UART2, baud=115200, stream=dbg)

#pin_select U3TX=PIN_D11
#pin_select U3RX=PIN_D0
#use rs232(UART3, baud=9600, stream=rf)

#define rfConf Pin_D8
#define rfEnable Pin_F3

#define sw1 Pin_E6
#define sw2 Pin_E7
#define sw3 Pin_G6
#define sw4 Pin_G7


#define rl1 Pin_F0
#define rl2 Pin_F1
#define rl3 Pin_E0
#define rl4 Pin_E1


#define openCol1 Pin_E2
#define openCol2 Pin_E3
#define openCol3 Pin_E4
#define openCol4 Pin_E5


 
//PWM için tanımlama
//#pin_select OC1=PIN_B2
//#pin_select OC2=PIN_B1


#use i2c(MASTER, I2C1, FAST, stream=I2C_PORT1)


#define hiX(x) output_high(x)
#define loX(x) output_low(x)

#define disable 0
#define enable 1

#define debug



#define iAmAlive Pin_D7
#define ledIntRda Pin_D6
#define ledIntRda2 Pin_D5
#define ledIntRda3 Pin_D4
#define ledIntCN Pin_D3


//#define lcdBacklight Pin_B14

#define tSn 1000
#define tUzun 500
#define tOrta 100
#define tKisa 50
#define tMini 10
#define tMicro 1

PIC Functions

C/C++
PIC Mcu Functions
void hmtrp(u8 state)
{
   if (state==disable)
   {
      hiX(rfEnable);
      hiX(rfConf);
   }
   if(state==enable)
   {
      loX(rfEnable);
      hiX(rfConf);
   }
}




u1 readDevId(void)
{
   u8 sayac;
   char temp;
   readDevIDOk=0;
   for(sayac=0;sayac<19;sayac++)
   {
      temp=read_ext_eeprom(sayac + devIDAddr);
      if((temp>32)&&(temp<128))
      {
         devID[sayac]=temp;
         readDevIDOk++;
      }
      else
      {
          if(sayac>1)
          {
            devID[sayac]="\0";
          }
          
      }
      
   }
   devID[sayac]='\0';
   
   
   if(readDevIDOk>10)
   {
      //fprintf(comm_dbg,"dev_id=%s\r\n"dev_id);
      return 1;
   }
   else
   {
      return 0;
   }
   
   

}

void writeDevId(void)
{
   u8 sayac2;
   char chr;
   u16 addr;
   
   
   for(sayac2=0;sayac2<20;sayac2++)
   {
      addr=sayac2+devIDAddr;
      chr=devID[sayac2];
      write_ext_eeprom(addr,chr);
   }
}

void clearDevID()
{
   u8 sayac,addr;
   char chr;
   
   for(sayac=0;sayac<30;sayac++)
   {
      addr=sayac+devIDAddr;
      write_ext_eeprom(addr,0);
   }
}

void eepromWrTest()
{
   u8 sayac;
   fprintf(dbg,"eeprom Write Test\r\n");
   for (sayac=1;sayac<20;sayac++)
   {
      write_ext_eeprom(sayac,65+sayac);
      bekle(tMini);
   }
}

void eepromRdTest()
{
   u8 sayac;
   char okunan[23];
   okunan[0]="A";
   for (sayac=1;sayac<20;sayac++)
   {
      okunan[sayac]=read_ext_eeprom(sayac);
      bekle(tMini);
   }
   okunan[sayac]=0;
   fprintf(dbg,"EEprom Test: %s\r\n"okunan);
   
}

Credits

Fikret

Fikret

25 projects • 38 followers
fidenetgaraj.blogspot.com

Comments