DigitalSignage with Raspberry Pi
This is an article about ** Digital Signage with Raspberry Pi **, which won the Raspberry Pi Foundation Award at ** Minna no Raspberry Pi Contest 2019 **. I made it with the aim of digitizing a paper bulletin board and replacing it easily.
pydrive (Google Drive API)
pdf2image
PIL
tkinter
Allow your account access to the Google Drive API and projects using Google Oauth
Main.py
gauth = GoogleAuth()
drive = GoogleDrive(gauth)
files = os.listdir('./data/')
count = len(files)
dirtxt = 'dirdata.txt'
The ScanPDF
folder will be created at the first link.
After that, the corresponding folder will be acquired.
Main.py
if not os.path.isfile(dirtxt):
folder = drive.CreateFile({
'title': 'ScanPDF',
'mimeType': 'application/vnd.google-apps.folder'
})
folder.Upload()
with open(dirtxt, mode='w') as f:
f.write(folder['id'])
dir_id = folder['id']
else:
with open(dirtxt) as f:
dir_id = f.read()
The user adds the PDF file they want to display on the signage to the ScanPDF
folder.
After that, when the inside of the folder is scanned, the added PDF will be displayed on the LCD.
Main.py
def scan(self):
global count
404img_path = "./data/404.png "
tmp_dir = "./tmp/"
shutil.rmtree(tmp_dir)
os.mkdir(tmp_dir)
i = 1
query = f"'{dir_id}' in parents and trashed=false"
try:
for file_list in drive.ListFile({'q': query, 'maxResults': 100}):
for file in file_list:
if file['mimeType'] == 'application/vnd.google-apps.folder':
pass
else:
file.GetContentFile(f'./tmp/{i+1}.pdf')
i += 1
except Exception as e:
print(e)
files = os.listdir(tmp_dir)
count = len(files)
if os.path.isfile(404img_path):
os.remove(404img_path)
if count == 0:
shutil.copy('404.png', 404img_path)
shutil.rmtree(tmp_dir)
os.mkdir(tmp_dir)
else:
for i in range(0, count):
shutil.copy(f'./tmp/{i+1}.pdf',
f'./data/{i+1}.pdf')
files = os.listdir('./data/')
Main.py
image = convert_from_path(f'./data/{cnt % (count) + 1}.pdf')
tmp = image[0].rotate(90, expand=True).resize((sw, sh))
self.img = ImageTk.PhotoImage(tmp)
self.canvas.itemconfig(self.imgArea, image=self.img)
Since the Google Drive folder is used as the file storage location, you can update it even when you are out. Furthermore, it is possible for multiple people to update by setting the access authority to the folder. Since the Raspberry Pi itself takes up almost no space, the compactness depends on the thinness of the liquid crystal. We are currently introducing this system as a contact bulletin board for university laboratories, and it is working well. We do not consider security issues.
** We welcome Pururiku Tsukkomi. Come thank you**
Recommended Posts