Touch pHAT and Scroll pHAT HD on Zero

Hi guys,
I’ve just entered the community and I have a little question for you (maybe a couple ;-) ).
I have a Raspberry Pi Zer0 which I would like to use together with the Touch HAT and Scroll pHAT HD on Zero, to realize a smaller version of the LaMetric Time.

I understood that it’s possible to combine a couple of HAT together using the Mini Black HAT Hack3r, is that correct?

If I can combine together the HAT, do you think in your experience, that there could be some conflicts at GPIO level?
I’ve read other topics on the forum and I checked the pinout: if I understood correctly, the two HAT communicate over the I2C but since the addresses are different I should be able to control both HAT successfully. Am I correct with my interpretation?

Alternatively, if it’s not possible to combine the two HATs, do you think that the Adafruit 16x2 LCD+Keypad could work with my Raspberry Pi Zero?

Thanks a lot

Kyashan

Neither of those pHATs use any pins but i2c* which means- as long as they have different i2c addresses (they do) - they will both work on the same Pi.

*See: https://pinout.xyz/pinout/scroll_phat and https://pinout.xyz/pinout/touch_phat

So, yes, you are correct!

Sometimes i2c devices might use other pins for functions such as interrupt, or other features on the board, so there can be conflicts, but in this case there aren’t. We’re also quite careful with our boards to avoid any i2c address overlap, it’s not always possible, but we try!

Thanks for the reply Gadgetoid.
That’s a very good news.
I’m going to order soon the HATs I need for my little project.

I wish you a nice day.

Hi Gadgetoid,
I have received my little pHats and I’m starting to code to let them serve my purposes.
The idea is to use the Touch pHat to navigate to a menu and choose some apps, run them and show the results on the Scroll pHat HD.

I’m a beginner coder with Python and till now I have developed a script to handle the buttons and move through the menu and choose the apps (using a couple of global variables to check if you’re in an app or still in the main menu).

The code is the following one:
#!/usr/bin/python
# This Python file uses the following encoding: utf-8

import signal
import time
import touchphat as tp
import scrollphathd as sphd

def clear_sphd():
  sphd.clear()
  sphd.show()

def write_sphd(text):
  clear_sphd()
  sphd.set_brightness(0.4)
  sphd.write_string(text + "    ", x=17, y=0)
  sphd.show()

def main_menu():

  @tp.on_release('Back')
  def handle_touch(event):
    global main
    global app
    if app == 1:
      print “You’re inside an app, to exit press B”
    else:
      #write_sphd(main)
      main -= 1
      print main

  @tp.on_release('Enter')
  def handle_touch():
    global main
    global app
    if app == 1:
      print "You’re inside an app, to exit press B"
    else:
      #write_sphd(main)
      main += 1
      print main


  @tp.on_release('A')
  def handle_touch(event):
    global main
    global app
    if app == 0:
      #write_sphd(main)
      app = 1
      print “You’re entering an app”
      print “The application number is ” , main
    else:
      print “You’re already in the app number“, main
      print “If you want to exit press B“

  @tp.on_release('B')
  def handle_touch(event):
    global main
    global app
    if app == 1:
      #write_sphd(main)
      print “You’re exiting the app”
      print “and going back to the main menu, where you left: ”, main
      app = 0
    else:
      print “This is not allowed in the main menu”
      print “Enter an app pressing the A button”

  signal.pause()

main = 0
app = 0
main_menu()

Once inside an app, I’d like to run a function to display the app name on the scroll pHat (write_sphd(main) commented out now) and subsequently call another function to run the real app. But I’m facing an error (see below) and I can’t understand why.

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 231, in run
    if self.todo() == False:
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 457, in _poll
    self._handle_alert()
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 450, in _handle_alert
    self._trigger_handler(x, inputs[x])
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 466, in _trigger_handler
    self.handlers[event][channel](channel, event)
TypeError: _handle_release() takes exactly 1 argument (2 given)

Please, could you help me to understand what I’m doing wrong?

Thanks in advance.

Kyashan

  @tp.on_release('Enter')
  def handle_touch():

Needs to be:

  @tp.on_release('Enter')
  def handle_touch(event):

The call stack is fairly uninformative in this instance, but it’s basically saying that the function you bound to handle release events on buttons is not accepting the arguments supplied to it.

The numbers are also a bit misleading. The 1 argument it mentions is Python’s self, so the two given are self, event.

Hi Gadgetoid,
thanks for the quick reply.

I have amended the line but unfortunately, I’m still receiving the same error.

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 231, in run
    if self.todo() == False:
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 457, in _poll
    self._handle_alert()
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 450, in _handle_alert
    self._trigger_handler(x, inputs[x])
  File "/usr/lib/python2.7/dist-packages/cap1xxx.py", line 466, in _trigger_handler
    self.handlers[event][channel](channel, event)
TypeError: _handle_release() takes exactly 1 argument (2 given)

Is it possible to call a function inside the handle_touch(event) function?

Sorry I was slightly wrong, all of your declarations for def handle_touch(event): should be def handle_touch(channel, event):

See:

    self.handlers[event][channel](channel, event)
TypeError: _handle_release() takes exactly 1 argument (2 given)

Presumably this error occurs on any button press?

Yes, the error occurs on any button press.

I have changed the declarations for def handle_touch, so now they are like that:
def handle_touch(channel, event):
but the error is still there.

Furthermore, if comment out the
write_sphd(main)
the error doesn’t disappear.

EDIT:
I found the error!!!
The function write_sphd(main) has to be written write_sphd(str(main)) because it accepts strings and not integers like in my examples.
Unfortunately, Python was giving me a misleading error message and I thought there was something in the way I was declaring the handle_touch function.

Thanks, Gadgetoid for the support!