I2C (OLED SSD1306) on Orange Pi R1 Plus LTS with OpenWrt - python-3.x

I'm new to OpenWrt but I have about a year of self-project (college final project, to be exact) experience using Linux in Raspberry Pi.
Have anyone here used I2C OLED SSD1306 on Orange Pi R1 Plus LTS with OpenWrt? I'm stuck now with the problem of enabling it.
I use OpenWrt 21.02.2, r16495-bf0c965af0.
Here's what I have tried: I used this library: https://github.com/karabek/OrangePi-OLED, and I tried to detect the i2c on bus 0 and 1 to get the device address, and I ran the demo file from the library. I expected the device to be able to run the i2c device on the detected port and address correctly.
When I tried to detect the i2c on bus 0 and 1, here's the output:
root#OpenWrt:~# i2cdetect -y 0
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory
root#OpenWrt:~# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
And then I modified the demo file from the library:
device = ssd1306(port=1, address=0x18)
And I run it. Here's what I got
root#OpenWrt:/mnt/OrangePi-OLED/examples# python3 demo.py
Traceback (most recent call last):
File "/mnt/OrangePi-OLED/examples/demo.py", line 11, in <module>
device = ssd1306(port=1, address=0x18)
File "/usr/lib/python3.9/site-packages/oled/device.py", line 163, in __init__
self.command(
File "/usr/lib/python3.9/site-packages/oled/device.py", line 73, in command
self.bus.write_i2c_block_data(self.addr, self.cmd_mode, list(cmd))
OSError: [Errno 16] Resource busy
I suspect this is because of the bus 0 is not enabled yet, as here is what the documentation says
Orange Pi R1 Plus LTS Documentation
But the OpenWrt version I'm using doesn't have the boot folder.
What is the solution?
Also, if it turns out I can't use I2C, what display should I use? Can I use SPI TFT IPS or UART display?

Related

Issue reading I2C with BPi with Raspbian Stretch OS

I am working with a BPi and I would like to read an CAN to I2C module connected to the SCL and SCA pins of the BPi.
When I try to detect the module, it seems to work fine, as i run i2cdetect -y 0 and the module with address 0x25 appears as follows:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- 25 -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Then, I try the i2cget -y 0 0x25 0 command, and something strange happens. I tried it once, and it returned 0x00, and after that, every time I run the same command, it pops up an error Error: Read failed.
Just as additional information, I am using a LoganLabs I2C-CAN module and a BPi with the Raspbian Stretch OS. I have the CAN module connected to a kvaser in which a CAN message is sent, so I think I should be able to read something with this commands.
I am trying to run this commands on the command window as a debbuging process, as I t also tried with the following code above, which simply returns "None".
from smbus2 import SMbus, i2c_msg
import time
address=25
def func1():
lect=i2c_msg.read(address,0)
while True:
lecture1=func1()
print(lecture1)
time.sleep(1)
'''
It returns: None
'''

RPI3B BME280 AttributeError: 'module' object has no attribute 'load_calibration_params'

I'm trying to get the following code working after battling with an smbus2 error i now find i have the following error and can't find how to fix it.
I know the sensor is working because if I run bme280.py from http://www.raspberrypi-spy.co.uk/ that works ok.
So my error is:
pi#wpi:~/weather $ python bme280_sensor.py
Traceback (most recent call last):
File "bme280_sensor.py", line 9, in <module>
bme280.load_calibration_params(bus, address)
AttributeError: 'module' object has no attribute 'load_calibration_params'
i2detect
pi#wpi:~/weather $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
Code not working: from https://pypi.org/project/RPi.bme280/
import smbus2
import bme280
port = 1
address = 0x76
bus = smbus2.SMBus(port)
calibration_params = bme280.load_calibration_params(bus, address)
# the sample method will take a single reading and return a
# compensated_reading object
data = bme280.sample(bus, address, calibration_params)
# the compensated_reading class has the following attributes
print(data.id)
print(data.timestamp)
print(data.temperature)
print(data.pressure)
print(data.humidity)
# there is a handy string representation too
print(data)
Found my issue posting it here in case any other newbies have the same issue!
I had a file called bme280.py in the same folder so it was loading that file instead of the correct bme280 library.
The solution was simply to rename that file.
Mine worked after I installed RPi.bme280
$ sudo pip3 install RPi.bme280
This is from the bme280 documentation:
https://github.com/rm-hull/bme280

Only doctests on immediate module

If I have three modules:
-- A.hs
module A where
-- $
-- >>> True
-- True
-- B.hs
module B where
import A
-- $
-- >>> True
-- True
-- C.hs
module C where
import B
-- $
-- >>> True
-- True
Running doctest C.hs will run all the doctests in all three files.
$ doctest C.hs
Examples: 3 Tried: 3 Errors: 0 Failures: 0
Is there a way to run doctest on only the top-level module - that is, have it not recursively search for tests in included modules?

Using WinGHCi to implement first Haskell program

This is not my code :
import Data.Monoid (Endo (..), appEndo)
import Data.Foldable (foldMap)
-- | chainEndos chain a list of endomorphisms to create a new one
-- Point-free version is feasible and redable.
-- Level: Easy
--
-- Examples:
--
-- >>> chainEndos [(+1),(*3)] 2
-- 7
-- >>> chainEndos [('h':),('e':)] "llo"
-- "hello"
--
-- >>> chainEndos [] (12 :: Int)
-- 12
--
chainEndos :: [a->a] -> a -> a
chainEndos = appEndo . foldMap Endo
chainEndos' :: [a->a] -> a -> a
chainEndos' = foldr (.) id
main = print $ chainEndos [('h':),('e':)] "llo"
I would like to run this in the Haskell IDE : http://www.haskell.org/platform/
But WinGhci offers just a repl like structure ? How can I load this as haskell file and run it ?
Save it to file, then
File -> Load
that's all, after it you can call main

OMAP 3 Linux I2C SMBUS SmartBattery (SBS) not Detected

I am working on an embedded Linux project with the OMAP 3730. We are using version 3.2.23 of the Kernel. I2C works fine and I can see various sensors from the board on bus #2. I2C bus #3 only has a Smart Battery attached and I can remove the power cord and the battery keeps the board running. The issue is that I cannot detect or otherwise scan for the smart battery. I've tried the various programs in i2ctools with no luck. We hooked the board up to the scope and can see activity on the bus #3. I have also enabled every pertinent option under the Device Drivers > I2C Support in the Kernel.
How can I view my smart battery on the i2c bus? Do I need to enable something else in the Kernel?
Standard SMBus slave address assignments for SBS devices include:
0x10 -- SMBus System Host
0x12 -- Smart Battery Charger
0x14 -- Smart Battery Selector
0x16 -- Smart Battery
# ls /dev/i2c-?
/dev/i2c-1 /dev/i2c-2 /dev/i2c-3
# i2cget -y 3 0x10 0x00 w p
Error: Read failed
#
# i2cget -y 3 0x0b 0x00 w p
Error: Read failed
# i2cdetect -r 3
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-3 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
# i2cdetect -F 3
Functionalities implemented by /dev/i2c-3:
I2C yes
SMBus Quick Command no
SMBus Send Byte yes
SMBus Receive Byte yes
SMBus Write Byte yes
SMBus Read Byte yes
SMBus Write Word yes
SMBus Read Word yes
SMBus Process Call yes
SMBus Block Write yes
SMBus Block Read no
SMBus Block Process Call no
SMBus PEC yes
I2C Block Write yes
I2C Block Read yes
# i2cdetect -l
i2c-1 i2c OMAP I2C adapter I2C adapter
i2c-2 i2c OMAP I2C adapter I2C adapter
i2c-3 i2c OMAP I2C adapter I2C adapter
The solution was to decrease the bus speed to 100 KHz for the bus that the gas gauge chip was on. After that I get:
# i2cdetect -y -r 3
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- 0b -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Resources