Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT / Q
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT / Q

by Madees on Fri Oct 22, 2021 1:47 pm

My brand new encoder send randomly some erronous values.

This is with RPI, Python 3 and seesaw module.

As I'm using it as an offset to my variables, I don't care of or see the "real" position value in my application, so I first thought about i2c bus EMC parasitic issue (even if my cables are just 15cm sourced adafruit QT to jumper on RPI GPIO PRODUCT ID: 4397), or au faulty encoder (also good quality sourced from adafruit PRODUCT ID: 377) with some non-stable position...

but when I did script log this issues, I saw that it happens only when position is 0 or negative ?
Here you'll see the log, I changed the value up and down by hand, but you'll notice easily the issue with "big number" (look like integer overflow ?) rise. Also, very quickly after, the encoder is sending the correct value...
Code: Select all | TOGGLE FULL SIZE
2021-10-22 00:23:24.061488 Encoder  0
2021-10-22 00:23:29.084299 Encoder  1
2021-10-22 00:23:29.194269 Encoder  0
2021-10-22 00:23:31.215784 Encoder  2147483648
2021-10-22 00:23:31.298040 Encoder  0
2021-10-22 00:23:33.586129 Encoder  2147483648
2021-10-22 00:23:33.655369 Encoder  0
2021-10-22 00:23:35.639740 Encoder  2147483648
2021-10-22 00:23:35.718702 Encoder  0
2021-10-22 00:23:44.408697 Encoder  2147483648
2021-10-22 00:23:44.479339 Encoder  0
2021-10-22 00:23:45.457427 Encoder  2147483648
2021-10-22 00:23:45.530120 Encoder  0
2021-10-22 00:24:01.634395 Encoder  2147483648
2021-10-22 00:24:01.700704 Encoder  0
2021-10-22 00:24:06.058554 Encoder  2147483648
2021-10-22 00:24:06.124283 Encoder  0
2021-10-22 00:24:15.458808 Encoder  2147483648
2021-10-22 00:24:15.516295 Encoder  0
2021-10-22 00:24:17.711986 Encoder  2147483648
2021-10-22 00:24:17.778592 Encoder  0
2021-10-22 00:24:25.355182 Encoder  2147483648
2021-10-22 00:24:25.418885 Encoder  0
2021-10-22 00:24:32.818460 Encoder  2147483648
2021-10-22 00:24:32.887307 Encoder  0
2021-10-22 00:24:39.193649 Encoder  1
2021-10-22 00:24:39.386683 Encoder  2
2021-10-22 00:24:39.641705 Encoder  3
2021-10-22 00:24:39.885151 Encoder  4
2021-10-22 00:25:19.258727 Encoder  5
2021-10-22 00:25:19.450820 Encoder  6
2021-10-22 00:25:20.253384 Encoder  7
2021-10-22 00:25:20.507786 Encoder  8
2021-10-22 00:25:20.684628 Encoder  9
2021-10-22 00:25:20.928576 Encoder  10
2021-10-22 00:25:21.120845 Encoder  11
2021-10-22 00:25:21.314997 Encoder  12
2021-10-22 00:26:19.996921 Encoder  11
2021-10-22 00:26:20.246455 Encoder  10
2021-10-22 00:26:20.612092 Encoder  9
2021-10-22 00:26:20.913214 Encoder  8
2021-10-22 00:26:21.149343 Encoder  7
2021-10-22 00:26:21.523770 Encoder  6
2021-10-22 00:26:22.828226 Encoder  5
2021-10-22 00:26:23.483645 Encoder  4
2021-10-22 00:26:24.626473 Encoder  3
2021-10-22 00:26:26.386266 Encoder  2
2021-10-22 00:26:27.948862 Encoder  1
2021-10-22 00:26:29.683195 Encoder  0
2021-10-22 00:26:32.520381 Encoder  2147483648
2021-10-22 00:26:32.588931 Encoder  0
2021-10-22 00:26:35.936263 Encoder  2147483648
2021-10-22 00:26:35.999719 Encoder  0
2021-10-22 00:26:52.583989 Encoder  2147483648
2021-10-22 00:26:52.655516 Encoder  0
2021-10-22 00:26:59.817951 Encoder  -1
2021-10-22 00:27:05.665391 Encoder  2147483647
2021-10-22 00:27:05.726627 Encoder  -1
2021-10-22 00:27:14.626798 Encoder  2147483647
2021-10-22 00:27:14.698215 Encoder  -1
2021-10-22 00:27:16.971518 Encoder  -2
2021-10-22 00:27:21.544429 Encoder  2147483646
2021-10-22 00:27:21.610818 Encoder  -2
2021-10-22 00:27:22.740997 Encoder  2147483646
2021-10-22 00:27:22.810091 Encoder  -2
2021-10-22 00:27:24.023510 Encoder  2147483646
2021-10-22 00:27:24.099388 Encoder  -2
2021-10-22 00:27:28.314716 Encoder  -3
2021-10-22 00:27:35.898383 Encoder  2147483645
2021-10-22 00:27:35.957033 Encoder  -3
2021-10-22 00:27:40.836003 Encoder  2147483645
2021-10-22 00:27:40.898733 Encoder  -3
2021-10-22 00:27:42.179959 Encoder  -4
2021-10-22 00:27:42.496824 Encoder  -5
2021-10-22 00:27:42.751270 Encoder  -6
2021-10-22 00:27:42.877776 Encoder  -7
2021-10-22 00:27:43.129115 Encoder  -8
2021-10-22 00:27:48.788200 Encoder  2147483640
2021-10-22 00:27:48.849475 Encoder  -8
2021-10-22 00:27:51.989765 Encoder  2147483640
2021-10-22 00:27:52.068335 Encoder  -8
2021-10-22 00:28:03.918966 Encoder  -9
2021-10-22 00:28:04.221018 Encoder  -10
2021-10-22 00:28:04.580675 Encoder  -11
2021-10-22 00:28:04.887301 Encoder  -12
2021-10-22 00:28:05.796625 Encoder  -13
2021-10-22 00:28:06.865308 Encoder  2147483635
2021-10-22 00:28:06.935132 Encoder  -13
2021-10-22 00:28:10.712195 Encoder  -12
2021-10-22 00:28:10.899939 Encoder  -11
2021-10-22 00:28:11.035570 Encoder  -10
2021-10-22 00:28:11.231939 Encoder  -9
2021-10-22 00:28:11.417570 Encoder  -8
2021-10-22 00:28:11.543630 Encoder  -7
2021-10-22 00:28:11.723511 Encoder  -6
2021-10-22 00:28:11.962737 Encoder  -5
2021-10-22 00:28:12.625142 Encoder  -4
2021-10-22 00:28:12.808525 Encoder  -3
2021-10-22 00:28:13.117280 Encoder  -2
2021-10-22 00:28:13.495106 Encoder  -1
2021-10-22 00:28:14.013394 Encoder  0
2021-10-22 00:28:22.231574 Encoder  1
2021-10-22 00:28:26.607684 Encoder  2
2021-10-22 00:28:29.907499 Encoder  3
2021-10-22 00:28:31.915038 Encoder  4
2021-10-22 00:28:37.939387 Encoder  5
2021-10-22 00:28:39.018500 Encoder  6
2021-10-22 00:28:39.455106 Encoder  7
2021-10-22 00:28:39.762195 Encoder  8
2021-10-22 00:28:40.079199 Encoder  9
2021-10-22 00:28:40.323931 Encoder  10
2021-10-22 00:28:40.764691 Encoder  11
2021-10-22 00:28:41.070342 Encoder  12
2021-10-22 00:28:41.202320 Encoder  13
2021-10-22 00:28:41.385966 Encoder  14
2021-10-22 00:28:41.508002 Encoder  15
2021-10-22 00:28:42.366954 Encoder  16
2021-10-22 00:28:42.614235 Encoder  17
2021-10-22 00:28:43.688639 Encoder  18
2021-10-22 00:28:44.776559 Encoder  19
2021-10-22 00:28:45.626016 Encoder  20
2021-10-22 00:28:46.172305 Encoder  21
2021-10-22 00:28:46.950488 Encoder  22
2021-10-22 00:28:48.029693 Encoder  23
2021-10-22 00:28:50.425033 Encoder  24
2021-10-22 00:28:52.640656 Encoder  25
2021-10-22 00:28:54.674926 Encoder  26
2021-10-22 00:28:54.914513 Encoder  27
2021-10-22 00:28:55.282852 Encoder  28
2021-10-22 00:28:55.597901 Encoder  29
2021-10-22 00:28:57.599595 Encoder  30
2021-10-22 00:28:57.790014 Encoder  31
2021-10-22 00:28:58.026826 Encoder  32
2021-10-22 00:28:58.147325 Encoder  33
2021-10-22 00:28:58.282231 Encoder  34
2021-10-22 00:28:58.462487 Encoder  35
2021-10-22 00:28:58.648114 Encoder  36
2021-10-22 00:28:59.838305 Encoder  37
2021-10-22 00:29:00.023083 Encoder  38
2021-10-22 00:29:00.153929 Encoder  39
2021-10-22 00:29:00.343600 Encoder  40
2021-10-22 00:29:00.471994 Encoder  41
2021-10-22 00:29:00.650975 Encoder  42
2021-10-22 00:29:00.905384 Encoder  43
2021-10-22 00:29:02.155952 Encoder  44
2021-10-22 00:29:02.346473 Encoder  45
2021-10-22 00:29:02.471654 Encoder  46
2021-10-22 00:29:02.596544 Encoder  47
2021-10-22 00:29:02.775668 Encoder  48
2021-10-22 00:29:02.967863 Encoder  49
2021-10-22 00:29:03.099632 Encoder  50
2021-10-22 00:29:04.434275 Encoder  51
2021-10-22 00:29:04.619613 Encoder  52
2021-10-22 00:29:04.756630 Encoder  53
2021-10-22 00:29:04.940481 Encoder  54
2021-10-22 00:29:05.081050 Encoder  55
2021-10-22 00:29:06.337156 Encoder  56
2021-10-22 00:29:06.521799 Encoder  57
2021-10-22 00:29:06.651456 Encoder  58
2021-10-22 00:29:06.773641 Encoder  59
2021-10-22 00:29:06.931146 Encoder  60
2021-10-22 00:29:06.998834 Encoder  61
2021-10-22 00:29:07.068491 Encoder  62
2021-10-22 00:29:07.195124 Encoder  63
2021-10-22 00:29:07.428393 Encoder  64
2021-10-22 00:29:08.881924 Encoder  65
2021-10-22 00:29:09.963469 Encoder  66
2021-10-22 00:29:10.218082 Encoder  67
2021-10-22 00:29:10.344036 Encoder  68
2021-10-22 00:29:10.463681 Encoder  69
2021-10-22 00:29:10.651434 Encoder  70
2021-10-22 00:29:10.834170 Encoder  71
2021-10-22 00:29:11.983548 Encoder  72
2021-10-22 00:29:12.108373 Encoder  73
2021-10-22 00:29:12.241693 Encoder  74
2021-10-22 00:29:12.306955 Encoder  75
2021-10-22 00:29:12.378525 Encoder  76
2021-10-22 00:29:12.464238 Encoder  78
2021-10-22 00:29:12.591860 Encoder  79
2021-10-22 00:29:12.661482 Encoder  80
2021-10-22 00:29:12.734703 Encoder  81
2021-10-22 00:29:13.654778 Encoder  82
2021-10-22 00:29:13.717407 Encoder  83
2021-10-22 00:29:13.807841 Encoder  84
2021-10-22 00:29:13.867777 Encoder  85
2021-10-22 00:29:13.928002 Encoder  86
2021-10-22 00:29:14.002205 Encoder  87
2021-10-22 00:29:14.082245 Encoder  88
2021-10-22 00:29:14.220215 Encoder  89
2021-10-22 00:29:14.292664 Encoder  90
2021-10-22 00:29:14.473545 Encoder  91
2021-10-22 00:29:14.720812 Encoder  92
2021-10-22 00:29:14.968842 Encoder  93
2021-10-22 00:29:15.154874 Encoder  94
2021-10-22 00:29:15.356736 Encoder  95
2021-10-22 00:29:26.600813 Encoder  94
2021-10-22 00:29:26.789624 Encoder  93
2021-10-22 00:29:26.981915 Encoder  92
2021-10-22 00:29:27.110161 Encoder  91
2021-10-22 00:29:27.232774 Encoder  90
2021-10-22 00:29:27.359248 Encoder  88
2021-10-22 00:29:27.430874 Encoder  87
2021-10-22 00:29:27.503657 Encoder  86
2021-10-22 00:29:27.589977 Encoder  85
2021-10-22 00:29:27.967810 Encoder  84
2021-10-22 00:29:28.036026 Encoder  82
2021-10-22 00:29:28.095033 Encoder  80
2021-10-22 00:29:28.158918 Encoder  77
2021-10-22 00:29:28.228694 Encoder  75
2021-10-22 00:29:28.653565 Encoder  73
2021-10-22 00:29:28.717778 Encoder  71
2021-10-22 00:29:28.797505 Encoder  69
2021-10-22 00:29:28.868268 Encoder  68
2021-10-22 00:29:28.932317 Encoder  67
2021-10-22 00:29:29.307215 Encoder  64
2021-10-22 00:29:29.370146 Encoder  62
2021-10-22 00:29:29.450382 Encoder  60
2021-10-22 00:29:29.523422 Encoder  58
2021-10-22 00:29:29.595301 Encoder  57
2021-10-22 00:29:29.983201 Encoder  56
2021-10-22 00:29:30.225501 Encoder  55
2021-10-22 00:29:30.303659 Encoder  54
2021-10-22 00:29:30.380286 Encoder  53
2021-10-22 00:29:30.441437 Encoder  52
2021-10-22 00:29:30.511231 Encoder  51
2021-10-22 00:29:30.636002 Encoder  50
2021-10-22 00:29:30.759521 Encoder  49
2021-10-22 00:29:31.247546 Encoder  48
2021-10-22 00:29:31.308085 Encoder  47
2021-10-22 00:29:31.384574 Encoder  46
2021-10-22 00:29:31.448912 Encoder  45
2021-10-22 00:29:31.542050 Encoder  43
2021-10-22 00:29:31.603864 Encoder  41
2021-10-22 00:29:31.684349 Encoder  39
2021-10-22 00:29:32.125534 Encoder  38
2021-10-22 00:29:32.198184 Encoder  37
2021-10-22 00:29:32.268905 Encoder  35
2021-10-22 00:29:32.349275 Encoder  34
2021-10-22 00:29:32.416927 Encoder  33
2021-10-22 00:29:32.493794 Encoder  32
2021-10-22 00:29:32.555462 Encoder  31
2021-10-22 00:29:32.638481 Encoder  30
2021-10-22 00:29:32.700098 Encoder  29
2021-10-22 00:29:33.614016 Encoder  28
2021-10-22 00:29:33.681043 Encoder  27
2021-10-22 00:29:33.748297 Encoder  25
2021-10-22 00:29:33.815939 Encoder  24
2021-10-22 00:29:33.886780 Encoder  22
2021-10-22 00:29:33.954345 Encoder  21
2021-10-22 00:29:34.020367 Encoder  20
2021-10-22 00:29:34.097440 Encoder  18
2021-10-22 00:29:34.161832 Encoder  17
2021-10-22 00:29:34.224475 Encoder  16
2021-10-22 00:29:34.303990 Encoder  15
2021-10-22 00:29:34.608652 Encoder  14
2021-10-22 00:29:34.678018 Encoder  11
2021-10-22 00:29:34.744428 Encoder  9
2021-10-22 00:29:34.816891 Encoder  6
2021-10-22 00:29:34.888828 Encoder  4
2021-10-22 00:29:35.319710 Encoder  2
2021-10-22 00:29:35.379226 Encoder  0
2021-10-22 00:29:35.464915 Encoder  -1
2021-10-22 00:29:35.527998 Encoder  -2
2021-10-22 00:29:35.599231 Encoder  -3
2021-10-22 00:29:36.559126 Encoder  -4
2021-10-22 00:29:36.751087 Encoder  -5
2021-10-22 00:29:36.810494 Encoder  -6
2021-10-22 00:29:38.605815 Encoder  -7
2021-10-22 00:29:38.673394 Encoder  -8
2021-10-22 00:29:38.735993 Encoder  -10
2021-10-22 00:29:38.801438 Encoder  -11
2021-10-22 00:29:38.868951 Encoder  -12
2021-10-22 00:29:38.931101 Encoder  -13
2021-10-22 00:29:39.534956 Encoder  -14
2021-10-22 00:29:39.601273 Encoder  -16
2021-10-22 00:29:39.667832 Encoder  -19
2021-10-22 00:29:39.732400 Encoder  -21
2021-10-22 00:29:39.792055 Encoder  -22
2021-10-22 00:29:39.887073 Encoder  -23
2021-10-22 00:29:40.424725 Encoder  -26
2021-10-22 00:29:40.488002 Encoder  -27
2021-10-22 00:29:40.556853 Encoder  -29
2021-10-22 00:29:40.638417 Encoder  -30
2021-10-22 00:29:46.583599 Encoder  2147483618
2021-10-22 00:29:46.645767 Encoder  -30
2021-10-22 00:29:56.865529 Encoder  2147483618
2021-10-22 00:29:56.934702 Encoder  -30
2021-10-22 00:30:11.210498 Encoder  2147483618
2021-10-22 00:30:11.273833 Encoder  -30
2021-10-22 00:30:19.340781 Encoder  2147483618
2021-10-22 00:30:19.399555 Encoder  -30
2021-10-22 00:30:20.723273 Encoder  2147483618
2021-10-22 00:30:20.798486 Encoder  -30
2021-10-22 00:30:27.960668 Encoder  2147483618
2021-10-22 00:30:28.024302 Encoder  -30


Thanks in advance for your help !

Madees
 
Posts: 5
Joined: Fri Oct 22, 2021 1:34 pm

Re: Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT

by adafruit_support_bill on Sat Oct 23, 2021 5:41 am

That does look suspiciously like integer overflow or a signed/unsigned data type mismatch. 2147483648 is 2^31.

I'll mention that to the CircuitPython team.

adafruit_support_bill
 
Posts: 82459
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT

by adafruit2 on Sat Oct 23, 2021 11:46 am

can you post your exact code you're running? its def some sign-unpacking thing

adafruit2
Site Admin
 
Posts: 20358
Joined: Fri Mar 11, 2005 7:36 pm

Re: Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT

by Madees on Sat Nov 06, 2021 4:14 pm

Hi !
Sorry for late reply, I was away from my computer and internet since a couple of week.

Here is the full code:
Code: Select all | TOGGLE FULL SIZE
print("*** Greenut OSC Bridge ***")
print("v1.3 Mathieu Delquignies 22/10/2021")

# Import needed modules from osc4py3
# more infos :
# https://pypi.org/project/osc4py3/
from osc4py3.as_allthreads import *
from osc4py3 import oscmethod as osm
from osc4py3 import oscbuildparse

# Import needed modules from Pi-Plates
# more infos :
# https://pi-plates.com/daqc2-users-guide/
import piplates.DAQC2plate as DAQC2

#Import needed modules from Adafruit
import board
from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio
from adafruit_ht16k33.segments import Seg14x4
 
# Import utilities from modules
from time import sleep
from sys import argv
import socket
import RPi.GPIO as GPIO
import datetime

print(str(datetime.datetime.now()), "All libs import OK.")
#####################
# Constants & Globals
#
displayText = ""

# CANs values buffer
prevCAN = [0,0,0,0,0,0,0,0,0]

# FREQ input buffer
prevFreq = 0

# DIN int flags
DINInterrupt = 0
DINByte = 0

# Network parameters
# Rx host
rxPort=50052
localIP=socket.gethostbyname(socket.gethostname())
# Tx host
txPort=50051
# Command line argument may be recipient IP, without arg it will be Local
if(len(argv)==2):
    ipAddress=argv[1]
else:
    ipAddress=localIP

#####################
# Callback functions
#

# Reply to ping
def ping():
    msg = oscbuildparse.OSCMessage("/pong", None, [])
    osc_send(msg, "OSCTx")
    print(str(datetime.datetime.now()), "Received a ping, answering pong.")
   

# Set DOUT
def OSCDOut(address, args):
    # convert output number in address String to Integer range (0-7)
    pinOut=int(address[len(address)-1])%8
    # set or clear corresponding DAQC2 plate output
    if (args==1):
        DAQC2.setDOUTbit(0, pinOut)
    else:
        DAQC2.clrDOUTbit(0, pinOut)
   

# Set RGB Led color
def OSCLEDColor(red, green, blue, alpha):
    pixel.fill((int(red*255), int(green*255), int(blue*255)))
   
   
# Print text
def OSCPrint(args):
    displayText=str(args)
    display.print("   " + displayText)
   

# Print text
def OSCMessage(args):
    display.marquee(str(args)+displayText, 0.25, False)
   

# get all Din values
def getDAQC2DIN():
    global DINInterrupt
    global DINByte
    # get DIN digital inputs values
    DINByte=DAQC2.getDINall(0)
    DINInterrupt=255
   
   
# DAQC2 Din Interrupt
def DAQC2Interrupt():
    global DINInterrupt
    global DINByte
    # get DIN digital inputs values
    DINByte=DAQC2.getDINall(0)
    # debounce button before clearing interrupt (! software deboucining slow down OSC send rate, including CANs)
    # sleep(0.01)
    DINInterrupt=DAQC2.getINTflags(0)
   
   
#
def intEnable():
    DAQC2.intEnable(0)
    print(str(datetime.datetime.now()), "DIN interrupts enabled.")
   

def intDisable():
    DAQC2.intDisable(0)
    print(str(datetime.datetime.now()), "DIN interrupts disabled.")
   

def OSCbrightness(args):
    display.brightness = args
   
   
def OSCblink(args):
    display.blink_rate = args
   
   
def OSCAOut(address, args):
    # convert output number in address String to Integer range (0-3)
    channel=int(address[len(address)-1])%4
    # set corresponding DAQC2 plate DA output voltage
    DAQC2.setDAC(0,channel,args)
    print(str(datetime.datetime.now()),"AOut #",channel," ",args)
   
   

#####################
#Functions

def testBit(int_type, offset):
    mask = 1 << offset
    return(bool(int_type & mask))

# Set Pi-PlatesRGB Led (for script only)
def PiPlateLED(args):
    # args is color as string: ‘off’, 'red’, ‘green’, ‘yellow’, ‘blue’, ‘magenta’, ‘cyan’, ‘white’
    DAQC2.setLED(0, args)
   
#####################
# Main
PiPlateLED("off")

# Board interrupt config for DIN triggers
# GPIO 22 is used as external interrupt from DAQC2. Enable interrupts on this pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# set interrupt callback
# ? strange behaviour of bouncetime>1, see sleep() in interrupt callback alternative ? worth check with GPIO module update
# put this in main loop instead of callback (following Jerry's instructions form Pi-plates)
# GPIO.add_event_detect(22, GPIO.FALLING, callback=DAQC2Interrupt, bouncetime=1)
# enable interrupt also on 0-7 DAQC2 Digital Inputs for both edges
for i in range(8):DAQC2.enableDINint(0, i, "b")
# reset interrupt flag, pin GPIO.22 should be high
DINInterrupt=DAQC2.getINTflags(0)
if (DAQC2.GPIO.input(22)==1): print(str(datetime.datetime.now()), "External interrupts OK.")

# Start the OSC system.
osc_startup()
print(str(datetime.datetime.now()), "OSC system started.")

# Make server channels to receive and send packets with LOCAL IP
osc_udp_server("127.0.0.1", rxPort, "OSCRx")
print(str(datetime.datetime.now()), "Local OSC server up and running on port "+str(rxPort)+" @"+localIP)
osc_udp_client(ipAddress, txPort, "OSCTx")
print(str(datetime.datetime.now()), "OSC client up and running on port "+str(txPort)+" @"+ipAddress)

# Associate Python functions with received message address patterns (default argument scheme OSCARG_DATAUNPACK)
osc_method("/ping", ping)
osc_method("/DOut/*", OSCDOut, argscheme=osm.OSCARG_ADDRESS + osm.OSCARG_DATAUNPACK)
osc_method("/LEDColor", OSCLEDColor)
osc_method("/print", OSCPrint)
osc_method("/message", OSCMessage)
osc_method("/getDIN", getDAQC2DIN)
osc_method("/intEnable",intEnable)
osc_method("/intDisable",intDisable)
osc_method("/brightness",OSCbrightness)
osc_method("/blink",OSCblink)
osc_method("/AOut/*", OSCAOut, argscheme=osm.OSCARG_ADDRESS + osm.OSCARG_DATAUNPACK)
print(str(datetime.datetime.now()), "OSC Rx parser up")

# Setup HUI on I2C bus with rotary encoder, RGB pixel and quad alphanumeric display
i2c = board.I2C()
seesaw = seesaw.Seesaw(i2c, 0x36)

encoder = rotaryio.IncrementalEncoder(seesaw)
last_position = -1

seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
button = digitalio.DigitalIO(seesaw, 24)
button_held = False

pixel = neopixel.NeoPixel(seesaw, 6, 1)

display = Seg14x4(i2c)
display.brightness = 0 # lowest as default, from 0 to 1 in 1/16 step

print(str(datetime.datetime.now()), "HUI setup OK")

print(str(datetime.datetime.now()), "Start event loop. Press Ctrl+c to stop.")
PiPlateLED("green")

#####################################################################################
# Start event loop
try:
    finished = False
    while not finished:
        # Process HUI rotary encoder to OSC
        # negate the position to make clockwise rotation positive
        position = -encoder.position
       
        # Don't know why sometimes encoder send this false value ? filter it out
        #if position == 2147483648:
        #    print(str(datetime.datetime.now()),"Encoder erronous value ?")
        #    position = last_position

        if position != last_position:
            last_position = position
            print(str(datetime.datetime.now()),"Encoder ",position)
            msg = oscbuildparse.OSCMessage("/encoder/", None, [position])
            osc_send(msg, "OSCTx")
       
        # Process HUI push button to OSC
        if not button.value and not button_held:
            button_held = True
            msg = oscbuildparse.OSCMessage("/button/", None, [1])
            osc_send(msg, "OSCTx")
           
        if button.value and button_held:
            button_held = False
            msg = oscbuildparse.OSCMessage("/button/", None, [0])
            osc_send(msg, "OSCTx")
                   
        # Process DIN to OSC
        # Check for DIN interrupts manually (RPI interrupt callback is de-activated)
        if (DAQC2.GPIO.input(22)==0): DAQC2Interrupt()
        if (DINInterrupt):
            if (DINInterrupt>255):
                print(str(datetime.datetime.now()), "Interrupt error ! "+str(DINInterrupt))
            else:
                for i in range(8):
                    if (testBit(DINInterrupt,i)):
                        msg = oscbuildparse.OSCMessage("/DIN/"+str(i), None, [int(testBit(DINByte,i)==True)])
                        osc_send(msg, "OSCTx")
            DINInterrupt=0
       
        # Process CANs to OSC
        # Get all 8 channels
        CAN=DAQC2.getADCall(0)
        for i in range(8):
            if prevCAN[i]!=CAN[i]:
                msg = oscbuildparse.OSCMessage("/CAN/"+str(i), None, [CAN[i]])
                osc_send(msg, "OSCTx")
                print("CAN",i)
                prevCAN[i]=CAN[i]
       
        # Process Freq In to OSC
        freq=DAQC2.getFREQ(0)
        if prevFreq!=freq:
            msg = oscbuildparse.OSCMessage("/freqIn", None, [freq])
            osc_send(msg, "OSCTx")
            prevFreq=freq
            print(str(datetime.datetime.now()),"freqIn ",freq)
       
        #Slow down to <50Hz
        sleep(0.02)
       
# Properly close the system.
except KeyboardInterrupt:
    print(str(datetime.datetime.now()), "OSCDAQC2Plate.py stopped by operator.")
   
osc_terminate()
print(str(datetime.datetime.now()), "OSC system stopped.")
PiPlateLED("red")
GPIO.cleanup()
print(str(datetime.datetime.now()), "GPIO interrupts cleaned.")




FYI if it helps, DAQC2 is a hat which uses SPI interface only. The only other device on I2C is the alpahnumeric display Quad Alphanumeric Display - Pure Green 0.54" Digits w/ Backpack[ID:2160].

Thanks a lot for your help,
Mat

Madees
 
Posts: 5
Joined: Fri Oct 22, 2021 1:34 pm

Re: Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT

by Madees on Fri Nov 12, 2021 11:08 am

Hi, I did get back to this project yesterday, now I also notice issues with the encoder board neopixel (not answering after the encoder send erronous values)... Alphanumeric display is working well. Do you think it can be an interference issue between the seesaw and ht16k33 modules ?

Madees
 
Posts: 5
Joined: Fri Oct 22, 2021 1:34 pm

Re: Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT

by Madees on Wed Nov 17, 2021 5:42 am

Without any feedback from you, I just get back to the test program using only I2C with encoder/neopixel https://github.com/adafruit/Adafruit_Ci ... eopixel.py

I get the same issues ! So it's definitely not a code or interference between modules error.
I get back to hardware issue, may be the cabling or the component ?

Madees
 
Posts: 5
Joined: Fri Oct 22, 2021 1:34 pm

Re: Adafruit I2C QT Rotary Encoder with NeoPixel - STEMMA QT

by Madees on Wed Nov 17, 2021 10:52 am

Hi, up...
Nobody has an idea ? I did double check connections, everything looks fine. Maybe an i2c pull-up issue ? Maybe worth try to lower protocol speed, or hardware wired lower impedance pull up ?...
My connection are RPI GPIO I2C>QT Encoder with Neopixel QT> soldered HT16k33 alphanumeric display. The display at the end of chain works like a charm.

Any idea about try outs would be much appreciated,
Thanks !

Madees
 
Posts: 5
Joined: Fri Oct 22, 2021 1:34 pm

Please be positive and constructive with your questions and comments.