Bonjour Sébastien,
Après l’étape de création de l’environnement constellation et création d’une sentinelle (une raspberry PI2).
Je tente des essais de programmation. L’étape en utilisant ton tuto LightSensor a été un réussite alors allont un peu plus lion.
J’ai suivi le très bon tuto http://hardware-libre.fr/2014/03/raspberry-pi-utiliser-un-lcd-4x20/ pour piloter un afficheur 2x16caractères et à nouveau une réussite.
Par contre le faire dans l’environnement constellation, et bien là c’est un achec. C’est là que j’ai besoin de tes conseils.
Je suis dans VS2015 voici mes codes:
Dans le Scripts: Constellation.py;i2c_lib.py; lcddriver.py et lightsensor.py.
i2c_lib.py:
import Constellation
import smbus
from time import *class i2c_device:
def init(self, addr, port=1):
self.addr = addr
self.bus = smbus.SMBus(port)Write a single command
def write_cmd(self, cmd):
self.bus.write_byte(self.addr, cmd)
sleep(0.0001)Write a command and argument
def write_cmd_arg(self, cmd, data):
self.bus.write_byte_data(self.addr, cmd, data)
sleep(0.0001)Write a block of data
def write_block_data(self, cmd, data):
self.bus.write_block_data(self.addr, cmd, data)
sleep(0.0001)Read a single byte
def read(self):
return self.bus.read_byte(self.addr)Read
def read_data(self, cmd):
return self.bus.read_byte_data(self.addr, cmd)Read a block of data
def read_block_data(self, cmd):
return self.bus.read_block_data(self.addr, cmd)
Constellation.WriteInfo("Librairie i2c_lib est chargée !")
Constellation.Start()
lcddriver.py:
import Constellation import i2c_lib from time import * # LCD Address ADDRESS = 0x3f # commands LCD_CLEARDISPLAY = 0x01 LCD_RETURNHOME = 0x02 LCD_ENTRYMODESET = 0x04 LCD_DISPLAYCONTROL = 0x08 LCD_CURSORSHIFT = 0x10 LCD_FUNCTIONSET = 0x20 LCD_SETCGRAMADDR = 0x40 LCD_SETDDRAMADDR = 0x80 # flags for display entry mode LCD_ENTRYRIGHT = 0x00 LCD_ENTRYLEFT = 0x02 LCD_ENTRYSHIFTINCREMENT = 0x01 LCD_ENTRYSHIFTDECREMENT = 0x00 # flags for display on/off control LCD_DISPLAYON = 0x04 LCD_DISPLAYOFF = 0x00 LCD_CURSORON = 0x02 LCD_CURSOROFF = 0x00 LCD_BLINKON = 0x01 LCD_BLINKOFF = 0x00 # flags for display/cursor shift LCD_DISPLAYMOVE = 0x08 LCD_CURSORMOVE = 0x00 LCD_MOVERIGHT = 0x04 LCD_MOVELEFT = 0x00 # flags for function set LCD_8BITMODE = 0x10 LCD_4BITMODE = 0x00 LCD_2LINE = 0x08 LCD_1LINE = 0x00 LCD_5x10DOTS = 0x04 LCD_5x8DOTS = 0x00 # flags for backlight control LCD_BACKLIGHT = 0x08 LCD_NOBACKLIGHT = 0x00 En = 0b00000100 # Enable bit Rw = 0b00000010 # Read/Write bit Rs = 0b00000001 # Register select bit class lcd: #initializes objects and lcd def __init__(self): self.lcd_device = i2c_lib.i2c_device(ADDRESS) self.lcd_write(0x03) self.lcd_write(0x03) self.lcd_write(0x03) self.lcd_write(0x02) self.lcd_write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE) self.lcd_write(LCD_DISPLAYCONTROL | LCD_DISPLAYON) self.lcd_write(LCD_CLEARDISPLAY) self.lcd_write(LCD_ENTRYMODESET | LCD_ENTRYLEFT) sleep(0.2) # clocks EN to latch command def lcd_strobe(self, data): self.lcd_device.write_cmd(data | En | LCD_BACKLIGHT) sleep(.0005) self.lcd_device.write_cmd(((data & ~En) | LCD_BACKLIGHT)) sleep(.0001) def lcd_write_four_bits(self, data): self.lcd_device.write_cmd(data | LCD_BACKLIGHT) self.lcd_strobe(data) # write a command to lcd def lcd_write(self, cmd, mode=0): self.lcd_write_four_bits(mode | (cmd & 0xF0)) self.lcd_write_four_bits(mode | ((cmd < MAX_READING): break reading += 1 return reading def Start(): global INTERVAL GPIO.setmode(GPIO.BCM) Constellation.OnExitCallback = OnExit lastSend = 0 currentValue = 0 count = 0 Constellation.WriteInfo("LightSensor + afficheur 2x16: status: Ok !") while Constellation.IsRunning: currentValue = currentValue + RCtime(LIGHT_SENSOR_GPIO) count = count + 1 ts = int(round(time.time())) if ts - lastSend >= int(Constellation.GetSetting("Interval")): avg = int(round(currentValue / count)) # on initialise le lcd lcd = lcddriver.lcd() # on reinitialise le lcd lcd.lcd_clear() # on affiche des caracteres sur chaque ligne lcd.lcd_display_string(" essai avec", 1) lcd.lcd_display_string(" Constellation", 2) #lcd.lcd_display_string(" un", 3) #lcd.lcd_display_string(" Raspberry Pi !", 4) Constellation.PushStateObject("Light", avg, "int") currentValue = 0 count = 0 lastSend = ts time.sleep(MEASURE_INTERVAL) Constellation.Start(Start)Dans App.config j'ai:
et dans le PackageInfo.xml j’ai fait évolué la version pour n’y retrouver.
Je fais une télédistribution dans la constellation et dans les log j’ai:
[raspfred1/LightSensor] 13:34:57 : ‘/opt/constellation-sentinel/Packages/LightSensor/Scripts/LightSensor.py’ is runningMais l’afficheur n’affiche pas le bon message “essais avec constelletion”
[raspfred1/LightSensor] 13:34:58 : Starting script ‘/opt/constellation-sentinel/Packages/LightSensor/Scripts/i2c_lib.py’
[raspfred1/LightSensor] 13:35:04 : Starting script ‘/opt/constellation-sentinel/Packages/LightSensor/Scripts/lcddriver.py’
[raspfred1/LightSensor] 13:35:04 : ‘/opt/constellation-sentinel/Packages/LightSensor/Scripts/i2c_lib.py’ is running
[raspfred1/LightSensor] 13:35:04 : ‘/opt/constellation-sentinel/Packages/LightSensor/Scripts/lcddriver.py’ is running
[raspfred1/LightSensor] 13:35:04 : Starting script ‘/opt/constellation-sentinel/Packages/LightSensor/Scripts/Script1.py’
[raspfred1/LightSensor] 13:35:04 : Librairie i2c_lib est chargée !
[raspfred1/LightSensor] 13:35:04 : Librairie i2c_lib est chargée !
[raspfred1/LightSensor] 13:35:04 : Librairie i2c_lib est chargée !
[raspfred1/LightSensor] 13:35:04 : ‘/opt/constellation-sentinel/Packages/LightSensor/Scripts/Script1.py’ is running
[raspfred1/LightSensor] 13:35:04 : Hi I’m ‘LightSensor’ and I currently running on raspfred1 and connected to Constellation
Ce qui est bizzare est que le message “Librairie lcddriver est chargée !” n’est pas dans le Log, par contre il y a 3 messages “Librairie i2c_lib est chargée !”.
Qu’est ce que je n’ai pas fait correctement?
Merci de ton aide.
Fréd