-- Config
local MISO = 5 --> GPIO14
local CLK = 6 --> GPIO12
local CS = 7 --> GPIO13
local duration = 3000 --> 3 seconds
local i = 0
local result = 0
-- Pin Initialization
gpio.mode(CS, gpio.OUTPUT)
gpio.mode(CLK, gpio.OUTPUT)
gpio.mode(MISO, gpio.INPUT)
gpio.write(CS,gpio.HIGH)
-- Function to read SPI
function readSPI()
gpio.write(CS, gpio.LOW) -->Activate the chip
tmr.delay(1) -->1us Delay
gpio.write(CLK, gpio.HIGH) -->First bit is dummy, ignore it(refer MAX6675 datasheet)
tmr.delay(2)
gpio.write(CLK, gpio.LOW)
tmr.delay(2)
result = 0
for i=15,1,-1
do
result = bit.lshift(result, 1)
result = bit.bor(result ,(bit.band(gpio.read(MISO),0x01)))
gpio.write(CLK, gpio.HIGH)
tmr.delay(2)
gpio.write(CLK, gpio.LOW)
tmr.delay(2)
end
if(bit.isset(result,2)) then
print("Sensor not connected")
gpio.write(CS, gpio.HIGH)
do return end
end
gpio.write(CS, gpio.HIGH)
print(bit.rshift(result,3)*0.25)
end
-- Create an interval
tmr.alarm(0, duration, 1, readSPI)
esp12 lua and mcp41100 pot. connection problem.
can ı help you?
spı connection error
I'm connecting cc1101 with esp8266-12e and connect pins like your connect.
This is my code:
#include "ELECHOUSE_CC1101.h"
void setup()
{
Serial.begin(9600);
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetReceive();
}
byte RX_buffer[61]={0};
byte size,i,flag;
void loop()
{
Serial.println("Received packet");
if(ELECHOUSE_cc1101.CheckReceiveFlag())
{
Serial.println("Received packet");
size=ELECHOUSE_cc1101.ReceiveData(RX_buffer);
for(i=0;i<size;i++)
{
Serial.print(RX_buffer[i],DEC);
Serial.print(' ');
}
Serial.println("");
ELECHOUSE_cc1101.SetReceive();
}
}
I tried with Arduino Uno success, but on esp always happen reboot
fets Jan 8 2013,rst cause:2, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset