Chat freely about anything...

User avatar
By Twin
#44258 Hello,

I would use the adc input of my ESP-07 but I do not know how to program, if someone just help me ?

Thank you
User avatar
By martinayotte
#44280 Before anyone try to help you, you need to do some homework ... ;-)
What kind of project you are planning ?
What things you will measure on the ADC ?
What speed/sampling-rate do you need ?
What framework you wish to use ? Arduino ? Sming ? plain SDK ?
User avatar
By Twin
#44526 - I want to connect the ESP-07 on humidity sensor (Module Arduino Wire TE215) I want to use the analog output to transmit to my Raspberry.
I used the data with Jeedom software.
I know that the limited entry is the ESP-07 1V I am a Resistive Voltage Divider (RVD).

-For My tests I want to send the value every 60 seconds, and then after I think every 1/2 hour.

-For Progammer I use CP2102 and LuaLoader or Arduino IDE software.
I think I get how to use adc grafted.
I want the value sent via a GET but I can not.
In LuaLoader, I have this error:
"> PANIC: unprotected error in call to Lua API (ds18b20.lua: 44: ow 1024 does not exist)"

I have followed this model and I try to suitable (sorry it's in French)

Here's what I'm doing


Code: Select all
-- On appelle le fichier ds18b20 uploadé plus tôt
require('ds18b20')
 
gpio0 = adc.read(0) -- Le gpio sur lequel est connecté la patte donnée du ds18b20
server_ip = "192.168.0.101" -- L'ip du serveur Jeedom
server_port = 80 -- Le port sur lequel vous voulez que votre serveur web écoute
api_key = "ZRN0DiluYXCLg4JZmUDHH6F9Z9Zt"
id_capteur = "11" -- A remplacer par votre id
 
-- Creation d'une fonction qui va récupérer la température
function gettemp(gpio)
  pin = gpio
  ds18b20.setup(pin)
  t1=ds18b20.read()
  return t1
end
 
-- Creation d'une fonction qui va préparer la requete a envoyer à Jeedom pour mettre notre capteur virtuel à jour.
function build_post_request(path, key, valueValue)
    payload = key .. "=" .. tostring(valueValue)
   
    return "POST " .. path .. " HTTP/1.1\r\n" ..
    "Host: " .. server_ip .. "\r\n" ..
    "Connection: close\r\n" ..
    "Content-Type: application/x-www-form-urlencoded\r\n" ..
    "Content-Length: " .. string.len(payload) .. "\r\n" ..
    "\r\n" .. payload
end
 
-- Création de la fonction qui envoit la requête à Jeedom
function send_temperature(valueValue)
    temp=gettemp(gpio0)
   block = true
    sk = net.createConnection(net.TCP, 0)
   
    sk:on("connection", function(sck)
        request = build_post_request("http://192.168.0.101/core/api/jeeApi.php?apikey=ZRN0DiluYXCLg4JZmUDHH6F9Z9Zt&type=httpRemoteEvent&eqId=11&value=valueValue" )
        sk:send(request, function()
            sk:close()
            block = false
        end)
    end)
   
    sk:connect(server_port, server_ip)
end
 
 
-- Configuration du serveur web
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    -- On décompose les url reçu et on place chaque bout dans des variables.
    conn:on("receive", function(client,request)
        local buf = "";
      temp=gettemp(gpio0)
 
        -- On définit l'aspect graphique de la page, le code HTML
        buf = buf.."<p>Il fait "..temp.." °C.";
 
        -- Cloture de la session
        client:send(buf);
        client:close();
        collectgarbage();
    end)
end)
 
-- On définit une boucle qui execute la fonction send_temperature(temp) toutes les minutes (60s)
tmr.alarm(0, 60000, 1, function() send_temperature(temp) end )


End :
Code: Select all--------------------------------------------------------------------------------
-- DS18B20 one wire module for NODEMCU
-- NODEMCU TEAM
-- LICENCE: http://opensource.org/licenses/MIT
-- Vowstar <vowstar@nodemcu.com>
-- 2015/02/14 sza2 <sza2trash@gmail.com> Fix for negative values
--------------------------------------------------------------------------------

-- Set module name as parameter of require
local modname = ...
local M = {}
_G[modname] = M
--------------------------------------------------------------------------------
-- Local used variables
--------------------------------------------------------------------------------
-- DS18B20 dq pin
local pin = nil
-- DS18B20 default pin
local defaultPin = 9
--------------------------------------------------------------------------------
-- Local used modules
--------------------------------------------------------------------------------
-- Table module
local table = table
-- String module
local string = string
-- One wire module
local ow = ow
-- Timer module
local tmr = tmr
-- Limited to local environment
setfenv(1,M)
--------------------------------------------------------------------------------
-- Implementation
--------------------------------------------------------------------------------
C = 0
F = 1
K = 2
function setup(dq)
  pin = dq
  if(pin == nil) then
    pin = defaultPin
  end
  ow.setup(pin)
end

function addrs()
  setup(pin)
  tbl = {}
  ow.reset_search(pin)
  repeat
    addr = ow.search(pin)
    if(addr ~= nil) then
      table.insert(tbl, addr)
    end
    tmr.wdclr()
  until (addr == nil)
  ow.reset_search(pin)
  return tbl
end

function readNumber(addr, unit)
  result = nil
  setup(pin)
  flag = false
  if(addr == nil) then
    ow.reset_search(pin)
    count = 0
    repeat
      count = count + 1
      addr = ow.search(pin)
      tmr.wdclr()
    until((addr ~= nil) or (count > 100))
    ow.reset_search(pin)
  end
  if(addr == nil) then
    return result
  end
  crc = ow.crc8(string.sub(addr,1,7))
  if (crc == addr:byte(8)) then
    if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then
      -- print("Device is a DS18S20 family device.")
      ow.reset(pin)
      ow.select(pin, addr)
      ow.write(pin, 0x44, 1)
      -- tmr.delay(1000000)
      present = ow.reset(pin)
      ow.select(pin, addr)
      ow.write(pin,0xBE,1)
      -- print("P="..present)
      data = nil
      data = string.char(ow.read(pin))
      for i = 1, 8 do
        data = data .. string.char(ow.read(pin))
      end
      -- print(data:byte(1,9))
      crc = ow.crc8(string.sub(data,1,8))
      -- print("CRC="..crc)
      if (crc == data:byte(9)) then
        t = (data:byte(1) + data:byte(2) * 256)
        if (t > 32767) then
          t = t - 65536
        end
        if(unit == nil or unit == C) then
          t = t * 625
        elseif(unit == F) then
          t = t * 1125 + 320000
        elseif(unit == K) then
          t = t * 625 + 2731500
        else
          return nil
        end
        t = t / 10000
        -- print("Temperature="..t1.."."..t2.." Centigrade")
        -- result = t1.."."..t2
        return t
      end
      tmr.wdclr()
    else
    -- print("Device family is not recognized.")
    end
  else
  -- print("CRC is not valid!")
  end
  return result
end

function read(addr, unit)
  t = readNumber(addr, unit)
  if (t == nil) then
    return nil
  else
    return t
  end
end

-- Return module table
return M


Thank you
Twin