Найти - Пользователи
Полная версия: Что не так в скрипте?
Начало » Python для новичков » Что не так в скрипте?
1
volt1000
Здравствуйте.
Есть малинка .к ней по I2C подключены 2 датчика INA219 для замера напряжения на АКБ 12В.Данные замера получаю на сервере APACHE2 .Мне необходимо получать данные сразу от 2-датчиков ,а в действительности получаю поочередно -от одного ,то от другого.
В скрипте уже все ,что знал по питону-все перепробовал-результат как описал выше.
    
import time
import board
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
i2c_bus = board.I2C()
ina219 = INA219(i2c_bus, 0x44)
print("ina219 test")
# display some of the advanced field (just to test)
print("Config register:")
print("  bus_voltage_range:    0x%1X" % ina219.bus_voltage_range)
print("  gain:                 0x%1X" % ina219.gain)
print("  bus_adc_resolution:   0x%1X" % ina219.bus_adc_resolution)
print("  shunt_adc_resolution: 0x%1X" % ina219.shunt_adc_resolution)
print("  mode:                 0x%1X" % ina219.mode)
print("")
# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
# optional : change voltage range to 16V
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V
# measure and display loop
while True:
    bus_voltage = ina219.bus_voltage        # voltage on V- (load side)
    shunt_voltage = ina219.shunt_voltage    # voltage between V+ and V- across the shunt
    current = ina219.current                # current in mA
    # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage
    with open ('/var/www/html/index.html','w') as f:
      print ("PSU Voltage:  {:6.3f} V".format(bus_voltage + shunt_voltage),file=f)
      print ("Shunt Voltage:{:9.6f} V".format(shunt_voltage),file=f)
      print ("Load Voltage: {:6.3f} V".format(bus_voltage),file=f)
      print ("Vsem privet",file=f)
    time.sleep(2)
"""Sample code and test for adafruit_in219"""
import time
import board
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
i2c_bus = board.I2C()
ina219 = INA219(i2c_bus)
print("ina219 test")
# display some of the advanced field (just to test)
print("Config register:")
print("  bus_voltage_range:    0x%1X" % ina219.bus_voltage_range)
print("  gain:                 0x%1X" % ina219.gain)
print("  bus_adc_resolution:   0x%1X" % ina219.bus_adc_resolution)
print("  shunt_adc_resolution: 0x%1X" % ina219.shunt_adc_resolution)
print("  mode:                 0x%1X" % ina219.mode)
print("")
# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
# optional : change voltage range to 16V
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V
# measure and display loop
while True:
    bus_voltage = ina219.bus_voltage        # voltage on V- (load side)
    shunt_voltage = ina219.shunt_voltage    # voltage between V+ and V- across the shunt
    current = ina219.current                # current in mA
    # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage
    with open ('/var/www/html/index.html','w') as f:
      print ("PSU Voltage:  {:6.3f} V".format(bus_voltage + shunt_voltage),file=f)
      print ("Shunt Voltage:{:9.6f} V".format(shunt_voltage),file=f)
      print ("Load Voltage: {:6.3f} V".format(bus_voltage),file=f)
      print ("Vsem privet",file=f)
    time.sleep(2)


Может ,кто глянет.
Спасибо
py.user.next
volt1000
Мне необходимо получать данные сразу от 2-датчиков ,а в действительности получаю поочередно -от одного ,то от другого.
Попробуй сначала просто поменять режим открытия файла на “w+”. Возможно, тебе этого хватит в плане “программирования”. Естественно, всё это по-другому должно выглядеть и рассказывать здесь это всё нет смысла, так как материала много и лучше тебе будет просто прочитать небольшое множество книг.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB