function convert_16_bit(msb, lsb, conv)--Returns a number, adjusted using the conversion factor. Use 1 if not desired res = 0 if msb >= 128 then res = (-0x7FFF+((msb-128)*256+lsb))/conv else res = (msb*256+lsb)/conv end return res end GNDAddr = 0x48 VDDAddr = 0x49 SDAAddr = 0x4A SCLAddr = 0x4B I2C.config(3, 2, 65516, 0, GNDAddr) MB.W(1000, 3, 3) --set DAC0 to 3v MB.W(1002, 3, 1.5) --set DAC1 to 2.5V --init MB.W(5104, 0, GNDAddr)--change target to 1st ads I2C.write({GNDAddr, 0x01, 0x02E2 })--ADS address, address pointer reg - 01:config reg 0000 0010 1000 0011 - change PGA etc. for real I2C.write({GNDAddr, 0x10, 0x8000 }) --ADS address, address pointer reg - 02:low_thresh reg I2C.write({GNDAddr, 0x11, 0x7FFF }) --ADS address, address pointer reg - 02:high_thresh reg I2C.write({GNDAddr, 0x00 })--ADS address, address pointer reg - 00:conversion reg --Begin loop LJ.IntervalConfig(0, 10) --change to 1000 while true do if LJ.CheckInterval(0) then MB.W(5104, 0, GNDAddr) Adata = {} dataIn = I2C.writeRead(GNDAddr, 2) table.insert(Adata, convert_16_bit(dataIn[1], dataIn[2], 1)) dataIn = I2C.writeRead(GNDAddr, 2) table.insert(Adata, convert_16_bit(dataIn[1], dataIn[2], 1)) --Report results to print() and User RAM-- MB.W(46180, 0, Adata[1]) MB.W(46181, 0, Adata[2]) print("A0: "..Adata[1].." A1: "..Adata[2]) print("------") end end