Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: Linkan on September 04, 2016, 07:29:16 AM

Title: py-smbus.tcz for picore 8
Post by: Linkan on September 04, 2016, 07: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 (https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=59808). Is it possible to install the python smbus package for picore 8?

Thanks.
Title: Re: py-smbus.tcz for picore 8
Post by: Linkan on September 04, 2016, 02: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'
Title: Re: py-smbus.tcz for picore 8
Post by: Linkan on September 04, 2016, 02:37:13 PM
Ok, nevermind it works. I just forgot to install python with `tce-load -wi python.tcz`  ::)