Skip to content

add support for esp32 and the whole house energy meter kit #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/atm90e32_u.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,40 @@
import time
import struct
from atm90e32_registers import *
import sys

SPI_WRITE = 0
SPI_READ = 1

class ATM90e32:
##############################################################################

def __init__(self, linefreq, pgagain, ugain, igainA, igainB, igainC):
def __init__(self, linefreq, pgagain, ugain, igainA, igainB, igainC, chipType='esp8266'):
self._linefreq = linefreq
self._pgagain = pgagain
self._ugain = ugain
self._igainA = igainA
self._igainB = igainB
self._igainC = igainC

# Chip select pin
self.cs = Pin(15, Pin.OUT)
self.cs.on()
# Doc on esp8266 SPI hw init: http://bit.ly/2ZhqeRB
self.spi = SPI(1, baudrate=200000, polarity=1, phase=1)
if chipType == 'esp8266':
# Chip select pin
self.cs = Pin(15, Pin.OUT)
self.cs.on()
# Doc on esp8266 SPI hw init: http://bit.ly/2ZhqeRB
self.spi = SPI(1, baudrate=200000, polarity=1, phase=1)

# this is setup to work with the energy meter kit http://bit.ly/2kWjpq8
elif chipType == 'esp32':
self.cs = Pin(5, Pin.OUT)
self.cs.on()

# Doc on esp32 SPI hw init: http://bit.ly/2kVLihW
self.spi = SPI(2, baudrate=200000, polarity=1, phase=1, bits=8, firstbit=0,
sck=Pin(18), mosi=Pin(23), miso=Pin(19))
else:
print('chip type not supported!')
sys.exit(0)

self._init_config()

Expand Down