WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: py-smbus.tcz for picore 8  (Read 2416 times)

Offline Linkan

  • Newbie
  • *
  • Posts: 27
py-smbus.tcz for picore 8
« on: September 04, 2016, 10:29:16 AM »
Hi, I have a rtc module based on DS3231N which has a built in temperature sensor which I would like to read from using python. I realize I need the smbus module for python to communicate via i2c. I found someone else wanting to do this over at the raspberry pi forum. Is it possible to install the python smbus package for picore 8?

Thanks.

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: py-smbus.tcz for picore 8
« Reply #1 on: September 04, 2016, 05:20:19 PM »
I tried running `wget http://tinycorelinux.net/7.x/armv6/tcz/py-smbus.tcz` and then `tce-load -i py-smbus.tcz`, but unfortunately that did not load the python module.
Code: [Select]
import smbus
import os

bus = smbus.SMBus(1)
address = 0x68

os.system('sudo rmmod rtc_ds1307')
def getTemp(address):
   byte_tmsb = bus.read_byte_data(address,0x11)
   byte_tlsb = bin(bus.read_byte_data(address,0x12))[2:].zfill(8)
   return byte_tmsb+int(byte_tlsb[0])*2**(-1)+int(byte_tlsb[1])*2**(-2)

print(getTemp(address))
os.system('sudo modprobe rtc_ds1307')
When I run the above below I get the following error:
Code: [Select]
Traceback (most recent call last):
  File "temperature.py", line 1, in <module>
ImportError: no module named 'smbus'
« Last Edit: September 04, 2016, 05:25:14 PM by Linkan »

Offline Linkan

  • Newbie
  • *
  • Posts: 27
Re: py-smbus.tcz for picore 8
« Reply #2 on: September 04, 2016, 05:37:13 PM »
Ok, nevermind it works. I just forgot to install python with `tce-load -wi python.tcz`  ::)