Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!

Electronic nose in the detection of the disease of the palms

Detection system of the disease called bud rot (PC-Pudrición de Cogollo) in the oil palm with the use of an electronic nose.

AdvancedShowcase (no instructions)944
Electronic nose in the detection of the disease of the palms

Things used in this project

Hardware components

Integrated circuit TL431BIP Texas Instrument
×1
Gas sensor TGS
×8
Gas sensor MQ
×8
Intel Galileo
×1
Integrated circuit TLC2543CN1 Texas Instruments
×1
Integrated Circuit TLV2543IN1 Texas Instruments
×1
Shield Sigfox Wisol
×1

Software apps and online services

Sigfox
Sigfox

Story

Read more

Schematics

Schematic of the 16 sensor plate

Code

Testing Sensors

Python
import os
import socket
import sys
import ast
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
from Personal_settings import *
from PROC_soft.funcionesadd import *


def testingsensors(IP,pathname):
	# Creando un socket TCP/IP
	dates=[]
	valmat=[]
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	Rl=10.0

	# Conecta el socket en el puerto cuando el servidor esté escuchando
	server_address = (IP, 10000)
	print >>sys.stderr, 'Conectando a %s puerto %s ...' % server_address
	try:
		sock.connect(server_address)

		try:
		    message = "sensordata"
		    # Enviando datos
		    print >>sys.stderr, 'enviando "%s"' % message
		    
		    sock.sendall(message)
		    data = sock.recv(4096)
		    print >>sys.stderr, 'recibiendo "%s"' % data
		    
		    if data == "sd":
		       	print "------------------------------------------- DATA ------------------------------------------------"
		       	fig, ax = plt.subplots()
		       	x=[]
		       	valmatp=[]
		       	i=0
		       	tvent=1000

	    		while True:
	    			i+=1
	    			data2= sock.recv(4096)
	    			msg1= sock.sendall("ok1")

	    			if data2 == "datef":
	    				fecha=sock.recv(4096)
	    				msg2= sock.sendall("ok2")
	    				dates.append(fecha)
	    				#print ""
	    				#print fecha

	    			elif data2 == "value":
	    				valstr=sock.recv(4096)#Recibo los datos en string
	    				msg3= sock.sendall("ok3")
	    				valint1=ast.literal_eval(valstr) #Conviento los valores a enteros
	    				####################
	    				valint=[round((((Rl*4096.0)/((med+1)*1.0))-Rl),3) for med in valint1]
	    				####################
	    				#print valint
	    				valmat.append((valint[0:8]+valint[14:22]))#Matriz con los datos
		    			ax.clear()
		    			if (i/2-1) > tvent:
		    				for j in range(tvent):
		    					x[j]=x[j+1]
		    					valmatp[j]=valmatp[j+1]
		    				x[tvent]=(i/2-1)
		    				valmatp[tvent]=valint
		    			else:
		    				x.append((i/2-1))
		    				valmatp.append(valint)
		    			minorLocatory=MultipleLocator(1)
		    			minorLocatorx=MultipleLocator(10)
		    			ax.yaxis.set_minor_locator(minorLocatory)
		    			ax.xaxis.set_minor_locator(minorLocatorx)
		    			ax.grid(which = 'minor')#True)
		    			ax.set_title("RESPONSE OF SENSORS - SENSITIVITY - Rs")
		    			ax.set_xlabel("Time [s]")
		    			ax.set_ylabel("Rs [KOhm]")
		    			ax.axis([x[0],x[(len(x)-1)]+1,0.1,10000])
		    			ax.plot(x,valmatp)
		    			plt.yscale('log', linthreshy=0.001)
		    			#handles, labels = ax.get_legend_handles_labels()
		    			ax.legend(["Sensor 1"," Sensor 2", "Sensor 3","Sensor 4"," Sensor 5", "Sensor 6", "Sensor 7"," Sensor 8", "Ref","Ref","Ref med", "Ref down", "Ref up", "vacio"," Sensor 9", "Sensor 10", "Sensor 11"," Sensor 12", "Sensor 13", "Sensor 14"," Sensor 15", "Sensor 16", "Ref","Ref","Ref med", "Ref down", "Ref up"], loc="upper left")
		    			#              dato1,      dato2,      dato3,      dato4,     dato5,      dato6,       dato7,     dato8,   dato9, dato10, dato11,   dato12,    dato13,     0,      dato14,      dato15,       dato16,     dato17,      dato18,      dato19,      dato20,     dato21,   dato22, dato23, dato24,   dato25,     dato26]   
		    			plt.pause(0.0000000000000000000000000000000001)
		    			print x[(len(x)-1)]
		    			print valint[0:8], " | ",valint[14:22]
	    			else:
	    				print "Error: Algun problema, el servidor no está enviando ni datef ni value"
	    				break
	    			

			else:
				print "Error: El servidor no respondio la clave correcta"
				dates=[0]
				valmat=[0]

		except KeyboardInterrupt:
			plt.close()
			londates=len(dates)
			lonvalmat=len(valmat)
			if lonvalmat < londates:
				valstr=sock.recv(4096)#Recibo los datos en string
				valint=ast.literal_eval(valstr) #Conviento los valores a enteros
				valmat.append(valint)#Matriz con los datos
				print valint
			elif lonvalmat > londates:
				print "Error: Se ha perdido una fecha, por lo tanto es mas grande la matriz de datos que la de fecha"

			while True:
				print ""
				print "Do you want to save the acquired data? Y/N"
				guard=raw_input(">> ")
				if guard.lower() in ["True", "yes", "y", "ok"]:
					print "Please enter a name for the sample file: "
					namefil=raw_input(">> ")
					modentrenam = True
					if modentrenam == True:
						try:
							os.makedirs("DAQ_soft/data_training/", 0755)
							os.makedirs("DAQ_soft/data_training/dates/", 0755)
						except:
							pass
						finally:	
							SaveListVariable(namefil, valmat, "DAQ_soft/data_training")
							SaveListVariable(namefil, dates, "DAQ_soft/data_training/dates")
							break
					else:
						try:
							os.makedirs("DAQ_soft/data_test/", 0755)
							os.makedirs("DAQ_soft/data_test/dates", 0755)
						except:
							pass
						finally:
							SaveListVariable(namefil, valmat, "DAQ_soft/data_test/")
							SaveListVariable(namefil, dates, "DAQ_soft/data_test/dates")
							break
				elif guard.lower() in ["no", "n", "not", "finish"]:
					break

				else:
					print ""
					print "Please enter a valid option"


		finally:
		    print >>sys.stderr, 'Closing socket ...'
		    sock.close()


		print "DATOS RECIBIDOS FINALMENTE"
		londates=len(dates)	
		lonvalmat=len(valmat)
		if lonvalmat == londates:
			print "         DATE        |                         DATA ADC1                            |                        DATA ADC2          "
			for i in range(0,londates):
				print dates[i], " | ", valmat[i][0:8], " | ", valmat[i][8:16]
		else:
			print "Tienen longitudes diferentes el vector de fechas y la matriz de datos"

		raw_input()
		
		return ("ready")
	except KeyboardInterrupt:
		print "Dirección IP no accesible"
		raw_input()
		return ("ready")

Credits

María Alejandra Lozano Jiménez
2 projects • 2 followers
Naren Arley Mantilla Ramírez
1 project • 2 followers

Comments