Adafruit is open and shipping! Let's build back better, together!
0

PiOLED Not working at all
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: PiOLED Not working at all

by crashmoon on Sat Dec 28, 2019 4:55 am

aphexx0407 wrote:Run the command ls /dev/i2c* /dev/spi*

You should get a response /dev/i2c-1 /dev/spidev0.0 /dev/spidev0.1

Also make sure you install the Python libraries


Yep, please see all 4 commands and their output in my screenshot. This command came back with the correct output.

I have also rebooted the Pi multiple times, checked that the stats.py is running and it is (see screenshot below) the process comes up twice because I've set it to start at boot and I manually started it as root to see if that worked but still nothing.
Attachments
statsdotpy.png
statsdotpy.png (144.66 KiB) Viewed 172 times
Last edited by crashmoon on Sat Dec 28, 2019 5:20 am, edited 1 time in total.

crashmoon
 
Posts: 7
Joined: Sat Dec 28, 2019 2:08 am

Re: PiOLED Not working at all

by crashmoon on Sat Dec 28, 2019 5:00 am

just for clarity, and being on a new page now:

Also I have a static IP set for the Pi and have set my routers DNS to the same as the Pi's IP address. Like I said initially, the Pi-hole works fine, just no stats (no anything) on my Oled screen
Attachments
PiOLED_setup.png
PiOLED_setup.png (60.78 KiB) Viewed 172 times

crashmoon
 
Posts: 7
Joined: Sat Dec 28, 2019 2:08 am

Re: PiOLED Not working at all

by aphexx0407 on Sat Dec 28, 2019 5:33 am

That's odd, so maybe it is. Have you reseated the PiOLED to the bieard as well?

aphexx0407
 
Posts: 44
Joined: Tue Sep 10, 2019 1:41 am

Re: PiOLED Not working at all

by crashmoon on Sat Dec 28, 2019 5:51 am

aphexx0407 wrote:That's odd, so maybe it is. Have you reseated the PiOLED to the bieard as well?

It actually looks like the screen is cracked at the top near the connection

:(
Attachments
pioledscreencrack.jpeg
pioledscreencrack.jpeg (424.73 KiB) Viewed 166 times

crashmoon
 
Posts: 7
Joined: Sat Dec 28, 2019 2:08 am

Re: PiOLED Not working at all

by aphexx0407 on Sat Dec 28, 2019 6:24 am

It does, contact aftersales support. They'd be more than happy to settle that for you

aphexx0407
 
Posts: 44
Joined: Tue Sep 10, 2019 1:41 am

Re: PiOLED Not working at all

by crashmoon on Sat Dec 28, 2019 7:04 am

aphexx0407 wrote:It does, contact aftersales support. They'd be more than happy to settle that for you


Willl do. Thanks for your help anyway :)

crashmoon
 
Posts: 7
Joined: Sat Dec 28, 2019 2:08 am

Re: PiOLED Not working at all

by adafruit_support_carter on Sat Dec 28, 2019 7:26 pm

@crashmoon It would also help if you could start a new thread for your issue. If support has already taken care of you, then no worries. But in general, it's best to always start a new thread for any new issue.

adafruit_support_carter
 
Posts: 18117
Joined: Tue Nov 29, 2016 2:45 pm

Re: PiOLED Not working at all

by curious on Wed Apr 29, 2020 8:56 pm

I have a working PiHole but decided to add the PiOLED to the existing Raspberry Pi. I followed the instructions on "Install PiOLED". Downloaded and installed all the packages. The little blinkatest.py program runs and gives the proper answers:
pi@pi-hole:~ $ python3 ~/Public/blinkatest.py
Hello blinka!
Digital IO ok!
I2C ok!
SPI ok!
done!

But when I run the stats.py program I get the following error message:
pi@pi-hole:~ $ sudo python3 ~pi/stats.py
Traceback (most recent call last):
File "/home/pi/stats.py", line 35, in <module>
from board import SCL, SDA
ImportError: No module named 'board'

The stats.py is copied straight from the adafruit site:
line 34 #Import Blinka
line 35 from board import SCL, SDA

My site-package library looks like I have all the relevant packages:
RPi.GPIO-0.7.0.dist-info digitalio.py Adafruit_Blinka-4.6.0.dist-info
RPi busio.py adafruit_blinka
pyusb-1.0.2.dist-info board.py
pyserial-3.4.dist-info bitbangio.py

Any idea why board is not getting imported and not providing the SCL and SDA?
curious
 
Posts: 10
Joined: Fri Jun 15, 2012 11:16 am

Re: PiOLED Not working at all

by aphexx0407 on Wed Apr 29, 2020 9:49 pm

Run the command ls /dev/i2c* /dev/spi*

You should get a response /dev/i2c-1 /dev/spidev0.0 /dev/spidev0.1

Also make sure you install the Python libraries

aphexx0407
 
Posts: 44
Joined: Tue Sep 10, 2019 1:41 am

Re: PiOLED Not working at all

by aphexx0407 on Wed Apr 29, 2020 9:52 pm

You haven't installed the Python Library, check this link

https://learn.adafruit.com/pi-hole-ad-b ... aries-6-10

aphexx0407
 
Posts: 44
Joined: Tue Sep 10, 2019 1:41 am

Re: PiOLED Not working at all

by curious on Wed Apr 29, 2020 10:36 pm

I ran the command
pi@pi-hole:~ $ ls /dev/i2c* /dev/spi*
/dev/i2c-1 /dev/spidev0.0 /dev/spidev0.1

so that looks good
Have done these installs:
sudo apt-get update
sudo apt-get upgrade
sudo pip3 install --setuptools
sudo pip3 install --upgrade setuptools
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
pip3 install RPI.GPIO
sudo pip3 install adafruit-circuitpython-ssd1306
sudo apt-get install python3-pil
sudo pip3 install requests

It's a long list. Looking at it got me wondering if I needed a sudo for the pip3 install RPI.GPIO. Tried that and system says "Requirement already satisfied: RPI.GPIO in /usr/lib/python3/dist-packages.

Still get the same message:
pi@pi-hole:~ $ sudo python3 ~pi/stats.py
Traceback (most recent call last):
File "/home/pi/stats.py", line 35, in <module>
from board import SCL, SDA
ImportError: No module named 'board'
curious
 
Posts: 10
Joined: Fri Jun 15, 2012 11:16 am

Re: PiOLED Not working at all

by aphexx0407 on Wed Apr 29, 2020 10:48 pm

Type again the command nano ~pi/stats.py and copy/paste the script stated here

https://learn.adafruit.com/pi-hole-ad-b ... ogram-6-24

aphexx0407
 
Posts: 44
Joined: Tue Sep 10, 2019 1:41 am

Re: PiOLED Not working at all

by curious on Thu Apr 30, 2020 2:53 pm

OK, pasted in the new copy of stats.py and got the same result.

pi@pi-hole:~ $ cat stats.py
# Copyright (c) 2017 Adafruit Industries
# Author: Ladyada, Tony DiCola & James DeVito
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# xxxxxxx FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# This example is for use on (Linux) computers that are using CPython with
# Adafruit Blinka to support CircuitPython libraries. CircuitPython does
# not support PIL/pillow (python imaging library)!

# Import Python System Libraries
import json
import subprocess
import time

# Import Requests Library
import requests

# Import Blinka
from board import SCL, SDA
import busio
import adafruit_ssd1306

# Import Python Imaging Library
from PIL import Image, ImageDraw, ImageFont

api_url = 'http://localhost/admin/api.php'

# Create the I2C interface.
i2c = busio.I2C(SCL, SDA)

# Create the SSD1306 OLED class.
# The first two parameters are the pixel width and pixel height. Change these
# to the right size for your display!
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)

# Leaving the OLED on for a long period of time can damage it
# Set these to prevent OLED burn in
DISPLAY_ON = 10 # on time in seconds
DISPLAY_OFF = 50 # off time in seconds

# Clear display.
disp.fill(0)
disp.show()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=0)

# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = -2
top = padding
bottom = height - padding
# Move left to right keeping track of the current x position
# for drawing shapes.
x = 0

# Load nice silkscreen font
font = ImageFont.truetype('/home/pi/slkscr.ttf', 8)

while True:
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=0)

# Shell scripts for system monitoring from here :
# https://unix.stackexchange.com/question ... d-cpu-load
cmd = "hostname -I | cut -d\' \' -f1 | tr -d \'\\n\'"
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "hostname | tr -d \'\\n\'"
HOST = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "top -bn1 | grep load | awk " \
"'{printf \"CPU Load: %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "free -m | awk 'NR==2{printf " \
"\"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
cmd = "df -h | awk '$NF==\"/\"{printf " \
"\"Disk: %d/%dGB %s\", $3,$2,$5}'"
Disk = subprocess.check_output(cmd, shell=True).decode("utf-8")

# Pi Hole data!
try:
r = requests.get(api_url)
data = json.loads(r.text)
DNSQUERIES = data['dns_queries_today']
ADSBLOCKED = data['ads_blocked_today']
CLIENTS = data['unique_clients']
except KeyError:
time.sleep(1)
continue

draw.text((x, top), "IP: " + str(IP) +
"( " + HOST + ")", font=font, fill=255)
draw.text((x, top + 8), "Ads Blocked: " +
str(ADSBLOCKED), font=font, fill=255)
draw.text((x, top + 16), "Clients: " +
str(CLIENTS), font=font, fill=255)
draw.text((x, top + 24), "DNS Queries: " +
str(DNSQUERIES), font=font, fill=255)

# skip over original stats
# draw.text((x, top+8), str(CPU), font=font, fill=255)
# draw.text((x, top+16), str(MemUsage), font=font, fill=255)
# draw.text((x, top+25), str(Disk), font=font, fill=255)

# Display image.
disp.image(image)
disp.show()
time.sleep(DISPLAY_ON)
disp.fill(0)
disp.show()
time.sleep(DISPLAY_OFF)


pi@pi-hole:~ $ sudo python3 ~pi/stats.py
Traceback (most recent call last):
File "/home/pi/stats.py", line 35, in <module>
from board import SCL, SDA
ImportError: No module named 'board'
pi@pi-hole:~ $
curious
 
Posts: 10
Joined: Fri Jun 15, 2012 11:16 am

Re: PiOLED Not working at all

by curious on Sat May 02, 2020 8:41 pm

#h
lsJust to add a little more mystery to my mystery I looked at my code to blinkatest.py:
pi@pi-hole:~ $ cat ~/Public/blinkatest.py
import board
import digitalio
import busio

print("Hello blinka!")

# Try to great a Digital input
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")

# Try to create an I2C device
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")

# Try to create an SPI device
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")

print("done!")

#and it works:
pi@pi-hole:~ $ python3 ~/Public/blinkatest.py
Hello blinka!
Digital IO ok!
I2C ok!
SPI ok!
done!

#Since blinkatest can import board with no problem, what is the difference between the programs. I tried using sudo with blinkatest and #got the following error:
pi@pi-hole:~ $ sudo python3 ~/Public/blinkatest.py
Traceback (most recent call last):
File "/home/pi/Public/blinkatest.py", line 1, in <module>
import board
ImportError: No module named 'board'

#So I don't get the board error if I don't use sudo. Why?

#That leads to the next question. Suppose I don't use sudo with the stats program, what happens?
pi@pi-hole:~ $ python3 stats.py
Traceback (most recent call last):
File "stats.py", line 37, in <module>
import adafruit_ssd1306
ImportError: No module named 'adafruit_ssd1306' #A different error, but board is no longer a problem.
#Checked to see if I had installed adafruit_ssd1306 #and found# $ sudo pip3 install adafruit-circuitpython-ssd1306
#should
37 import adafruit_ssd1306 #really be
37 import adafruit-circuitpython-ssd1306 #????
curious
 
Posts: 10
Joined: Fri Jun 15, 2012 11:16 am

Re: PiOLED Not working at all

by mikeysklar on Mon May 04, 2020 6:19 pm

Hi curious,

This is a common confusion with the circuitpython library installation. If the `pip install ...` was done with sudo then the python3 execution of the scripts will always need the sudo prefix to find the libraries. If the pip install was done without sudo then you will always need to call python3 without sudo.

mikeysklar
 
Posts: 2795
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.