You are reading a single comment by @lshk and its replies. Click here to read the full conversation.
  • Hi!
    I have an IR intervalometer for a Sony a7 camera on an Arduino Nano. It works great, but I need to implement the same on esp32.

    Arduino simplified code:

    unsigned long TimeBetweenShots = 2000;
    int IRled = 2;
    int Begin = 13;
    
    int SCodeBits[] = {1,0,1,1,0,1,0,0,1,0,1,1,1,0,0,0,1,1,1,1­};
    
    void setup()
    {
      pinMode(IRled, OUTPUT);
      pinMode(Begin, OUTPUT);
    }
     
    void loop()
    {
      static int delta = 0;
    
      delta+=100;
      
      digitalWrite(Begin, HIGH);
      
      for (int i=1; i <= 3; i++)
      {
        header();
        for (int i=0; i <= 19; i++)
        {
              if(SCodeBits[i] == 1)
              {
                Data_is_One();
              }
              else
              {
                Data_is_Zero();
              }
        }
        delay(11);
      }
      digitalWrite(Begin, LOW);
      delay(TimeBetweenShots+delta);
    }
    
    void burst()
    {
      digitalWrite(IRled, HIGH);
      delayMicroseconds(10);  
      digitalWrite(IRled, LOW);
      delayMicroseconds(8);
    }
    
    void quiet()
    {
      digitalWrite(IRled, LOW);
      delayMicroseconds(18);
    }
    
    void header() 
    {
        for (int i=1; i <= 96; i++){
          burst();
        }
        for (int i=1; i <= 24; i++){
          quiet();
        }
    }
    
    void Data_is_One()
    {
        for (int i=1; i <= 48; i++){
          burst();
        }
        for (int i=1; i <= 24; i++){
          quiet();
        }
    }
    
    void Data_is_Zero()
    {
        for (int i=1; i <= 24; i++){
          burst();
        }
        for (int i=1; i <= 24; i++){
          quiet();
        }
    }
    

    This is JS for Espruino, just for one shot:

    const IRled = D17;
    
    let SCodeBits = [1,0,1,1,0,1,0,0,1,0,1,1,1,0,0,0,1,1,1,1­];
    
    function shot(){
      pinMode(IRled,"output");
    
      function burst(){
        digitalPulse(IRled,1,[0.01,0.008]);
      }
    
      function quiet(){
        digitalPulse(IRled,0,0.018);
      }
    
      function header(){
        for (let i=0; i < 96; i++){
          burst();
        }
        for (let i=0; i < 24; i++){
          quiet();
        }
      }
      function  Data_is_One(){
        for (let i=0; i < 48; i++){
          burst();
        }
        for (let i=0; i < 24; i++){
          quiet();
        }
      }
      function Data_is_Zero(){
        for (let i=0; i < 24; i++){
          burst();
        }
        for (let i=0; i < 24; i++){
          quiet();
        }
      }
    
      for (let i=0; i < 3; i++){
        setTimeout(function() {
          header();
          for (let j=0; j < 20; j++){
              if(SCodeBits[j] === 1){
                Data_is_One();
              }
              else{
                Data_is_Zero();
              }
          }
          console.log('IR');
        }, 11);
      }
    }
    
    function onInit() {
      setTimeout(function() {
        shot();
      }, 1000);
    }
    

    And this code doesn't work... Where did I go wrong?

  • Sun 2021.09.12

    Hi @lshk it appears you may be the first with this specific device functionality.

    There seems to be an apparent mis-understanding of how Javascript timer events work in comparrison with Arduino delays.

    While Arduino code continually loops and toggles a pin with a delay, the timeout L57-L61 that triggers the L58 shot() function, will run after the timeout interval has elapsed.

    This will take a bit of finagling, but first check out with it's live online 'Try It' windows

    https://www.w3schools.com/js/js_timing.a­sp

  • Mon 2021.09.13

    Hi @lshk and thank you for the links post #5 to the overall project idea. I now have a better idea as to what functionality is required.

    re post #1: 'It works great, but I need to implement the same on esp32.'

    I note from your post #1 that you have existing 'C' source for Arduino. As I re-read the above requirement, it dawned on me a very basic question. Why not use the same code and just flash to the ESP32 from within the Arduino IDE?

    I could be missing something very basic, but this stood right out as I read back through the posts.

    Maybe you are in the process of creating an Instructable or tutorial to share here, done in Javascript instead? I'm curious, but it seems that is the easiest way to skin this cat!

About

Avatar for lshk @lshk started