# ZymKey problem when reading MCP3008

**URL:** <https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020>\
**Category:** ZYMKEY4\
**Created:** [November 19, 2020, 6:02pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020 "2020-11-19T18:02:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpiMike](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rpiMike](https://community.zymbit.com/u/rpiMike)\
**Post date:** [November 19, 2020, 6:02pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/1 "2020-11-19T18:02:36Z")

</div>

Using the latest Raspberry Pi OS 32bit, fully updated on a Pi4 2GB.

Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux

The ZymKey appears to work fine with the slow blue led blinking. Within a few seconds of starting code that reads MCP3008 over SPI the ZymKey flashes rapidly then gives 8 flashes which I believe is i2c comms problem.

The ZymKey port is configured to GPIO24.

```
from gpiozero import MCP3008
import time

voltages = []
voltages.append(MCP3008(channel=7))
voltages.append(MCP3008(channel=6))
voltages.append(MCP3008(channel=5))
voltages.append(MCP3008(channel=4))
voltages.append(MCP3008(channel=3))
voltages.append(MCP3008(channel=2))
    
while True:
    for voltage in voltages:
        print(str(voltage.value)+' ',end='')
    print('')    
    time.sleep(0.1)
```

---

<div class="post-metadata">

**Author:** ![Bob\_of\_Zymbit](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Bob\_of\_Zymbit](https://community.zymbit.com/u/Bob_of_Zymbit)\
**Post date:** [November 19, 2020, 7:04pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/2 "2020-11-19T19:04:05Z")

</div>

@rpiMike - Yes the 8 flashes is a comm problem on i2c.

The first question we always have to ask is do you have a good power supply?

Next, can you try changing the PI CPU scaling governor from **ondemand** to **performance** to see if that makes a difference? Details here:

[https://community.zymbit.com/t/dev-team-known-issues/996/3](https://community.zymbit.com/t/dev-team-known-issues/996/3)

And one more question on your setup: How is your MCP3008 wired up? Is it on a standard HAT, or are you wiring up yourself on a breadboard?

Bob

---

<div class="post-metadata">

**Author:** ![rpiMike](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rpiMike](https://community.zymbit.com/u/rpiMike)\
**Post date:** [November 19, 2020, 7:15pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/3 "2020-11-19T19:15:52Z")

</div>

I’m using an official Pi 2.5 Amp power supply into a PiJuice UPS mounted onto the Pi4. I’m not seeing any low power warnings.

I will try the governor change.

The MCP3008 is mounted onto a custom made PCB.

---

<div class="post-metadata">

**Author:** ![Bob\_of\_Zymbit](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Bob\_of\_Zymbit](https://community.zymbit.com/u/Bob_of_Zymbit)\
**Post date:** [November 20, 2020, 12:24am UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/4 "2020-11-20T00:24:17Z")

</div>

The Pi4 recommended power is at least 3.0A. If you have a better Power Supply, you may want to also give that a try.

[https://www.raspberrypi.org/documentation/hardware/raspberrypi/power/README.md](https://www.raspberrypi.org/documentation/hardware/raspberrypi/power/README.md)

---

<div class="post-metadata">

**Author:** ![rpiMike](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rpiMike](https://community.zymbit.com/u/rpiMike)\
**Post date:** [November 20, 2020, 12:00pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/5 "2020-11-20T12:00:48Z")

</div>

Tested with an official Pi 3.0Amp power supply direct into Pi4, same issue.

First command on your governor change fails:

```
pi@raspberrypi:~ $ 
pi@raspberrypi:~ $ echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
bash: /sys/devices/system/cpu/cpufreq/policy0/scaling_governor: Permission denied
pi@raspberrypi:~ $ sudo echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
bash: /sys/devices/system/cpu/cpufreq/policy0/scaling_governor: Permission denied
pi@raspberrypi:~ $
```

---

<div class="post-metadata">

**Author:** ![Bob\_of\_Zymbit](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Bob\_of\_Zymbit](https://community.zymbit.com/u/Bob_of_Zymbit)\
**Post date:** [November 20, 2020, 6:51pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/6 "2020-11-20T18:51:41Z")

</div>

It requires “sudo su”. Thanks for pointing that out. We added that note to our instructions.

---

<div class="post-metadata">

**Author:** ![rpiMike](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rpiMike](https://community.zymbit.com/u/rpiMike)\
**Post date:** [December 4, 2020, 12:32pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/7 "2020-12-04T12:32:18Z")

</div>

I’ve still got the same issue with this.

Created a service called ‘myservice’ as suggested. Using official 3.0A power supply.

```
pi@raspberrypi:~ $ sudo systemctl status myservice
● myservice.service - Set scaling governor to performance
   Loaded: loaded (/etc/systemd/system/myservice.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2020-12-04 12:25:09 GMT; 35s ago
  Process: 809 ExecStart=/bin/sh -c echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor (code=exited, status=
 Main PID: 809 (code=exited, status=0/SUCCESS)

Dec 04 12:25:09 raspberrypi systemd[1]: Starting Set scaling governor to performance...
Dec 04 12:25:09 raspberrypi systemd[1]: myservice.service: Succeeded.
Dec 04 12:25:09 raspberrypi systemd[1]: Started Set scaling governor to performance.
pi@raspberrypi:~ $ more /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
performance
pi@raspberrypi:~ $ 

```

Run my MCP3008 code from first post. Working ok so far.

Then try querying ZymKey:

```
import zymkey,time

zymkey.client.set_perimeter_event_actions(1, action_notify=True, action_self_destruct=False)

while True:
    try:
        zymkey.client.wait_for_perimeter_event(timeout_ms=1000)
        perim_status_str = ""
        idx = 0
        plst = zymkey.client.get_perimeter_detect_info()
        for p in plst:
            if p:
                perim_status_str += " perim%d timestamp = %d" % (plst.index(p), p)
        print("Perimeter event detected!" + perim_status_str)
        zymkey.client.clear_perimeter_detect_info()
    except zymkey.exceptions.ZymkeyTimeoutError:
        print("Nothing going on")
    except Exception as e:
        print(str(e))
    time.sleep(0.1)

```

Then get 8 flashes followed by just rapid flashes.

---

<div class="post-metadata">

**Author:** ![Bob\_of\_Zymbit](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Bob\_of\_Zymbit](https://community.zymbit.com/u/Bob_of_Zymbit)\
**Post date:** [December 4, 2020, 6:42pm UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/8 "2020-12-04T18:42:12Z")

</div>

@rpiMike - I’d like to find out a little more about your project. I’ll send you a DM from support outside the Community.

Bob

---

<div class="post-metadata">

**Author:** ![rpiMike](https://avatars.discourse-cdn.com/v4/letter/r/8baadc/32.png) [@rpiMike](https://community.zymbit.com/u/rpiMike)\
**Post date:** [December 7, 2020, 10:42am UTC](https://community.zymbit.com/t/zymkey-problem-when-reading-mcp3008/1020/9 "2020-12-07T10:42:16Z")

</div>

@Bob_of_Zymbit don’t seem to have received DM yet?
