Reading a register in Lua ESP8266-01
Posted: Thu Aug 06, 2015 5:48 am
Hey everyone,
i didnt get a simple read from a register function working. I got a ESP8266-01, that runs nodemcu. I just want to write to a conversion register of a MCP4725 DAC and than again read the value. But my output is alwas 255
heres my code:
write
than i want to read the register with this code:
hopefully someone could tell what im doing wrong
Edit: Ok saw my fault wrong read_reg function
now its this:
but anyway its now full of 0s
i didnt get a simple read from a register function working. I got a ESP8266-01, that runs nodemcu. I just want to write to a conversion register of a MCP4725 DAC and than again read the value. But my output is alwas 255
heres my code:
write
Code: Select all
id=0
sda=3
scl=4
i2c.setup(id, sda, scl, i2c.SLOW)
voltage=1
volt=(4096*voltage)/3.27 --the conversion
msb = bit.rshift(volt, 8)
lsb = volt-bit.lshift(msb,8)
print(lsb)
print(msb)
i2c.start(id)
i2c.address(id, 0x60,i2c.TRANSMITTER)
--i2c.write(id, 0x40)
i2c.write(id,msb)
i2c.write(id,lsb)
i2c.stop(id)
than i want to read the register with this code:
Code: Select all
id=0
sda=3
scl=4
i2c.setup(id, sda, scl, i2c.SLOW)
i2c.start(id)
i2c.address(id, 0x60,i2c.RECEIVER)
--i2c.write(id,0x40) also tried this
c=i2c.read(id,2)
h,i=string.byte(c,1,2)
print("MSB=",h)
print("LSB=",i)
i2c.stop(id)
hopefully someone could tell what im doing wrong
Edit: Ok saw my fault wrong read_reg function
now its this:
Code: Select all
i2c.start(id)
i2c.address(id, 0x60 ,i2c.TRANSMITTER)
i2c.write(id,0x40)
i2c.stop(id)
i2c.start(id)
i2c.address(id, 0x60,i2c.RECEIVER)
c=i2c.read(id,2)
c,h=string.byte(c,1,2)
print(c)
print(h)
i2c.stop(id)
but anyway its now full of 0s