Skip to content
  • 0 Votes
    2 Posts
    31 Views
    OldSurferDudeO
    I have success! (oops, that's suppose to be Timer1) I only sample for 1/60 of a second. What I did was to back up all the timer registered I used and then resorted them after I was done sampling. (As opposed to initializing the registers in setup and then starting the timer when needed.) Now I have a Nano sampling the data and sending it to a MySensors Gateway on an RPi3B+ which then sends it to an MQTT broker runing on an old laptop. Also running on the laptop is Home Assistant running inside of VirtualBox. If MySensors does use Timer1, it appears that restoring the registers allows it to be shared. //------------------------------------------------------ISR ISR(TIMER1_OVF_vect){ // interrupt service routine for overflow TCNT1 = TimerPreloadValue; // must be first line! starts the timer counting again digitalWrite(TRIGGER_START_SAMPLE_PIN,HIGH); samplesVolts[--sample]=analogRead(VOLTS_IN_PIN); // decrement before capturing samplesCurrent[sample]=analogRead(CURRENT_IN_PIN); digitalWrite(TRIGGER_START_SAMPLE_PIN,LOW); if (!sample){ // count down to zero digitalWrite(TRIGGER_START_SAMPLE_PERIOD_PIN,LOW); // indicate that sampling is complete samplingEnd = micros(); TCCR1B &= 248; // turns off timer } } //------------------------------------------------------sampleOneCycle void sampleOneCycle(){ // back up timer registers uint8_t TCNT1_b = TCNT1; uint8_t TCCR1B_b = TCCR1B; uint8_t TCCR1A_b = TCCR1A; uint8_t TIMSK1_b = TIMSK1; // configure timer which starts the sampling noInterrupts(); // disable all interrupts TCCR1A = 0; TCCR1B = 0; TCNT1 = TimerPreloadValue; // preload timer //TCCR1B |= (1 << CS10)|(1 << CS12); // 1024 prescaler TCCR1B &= 248; // turns off timer? TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt ISR // demark sampling sample = NUMBER_OF_SAMPLES; // count down to zero digitalWrite(TRIGGER_START_SAMPLE_PERIOD_PIN,HIGH); samplingStart = micros(); TCNT1 = 65535; // first trigger right away! TCCR1B |= 1; // turns on timer interrupts(); // enable all interrupts // wait for sampling to be complete while(digitalRead(TRIGGER_START_SAMPLE_PERIOD_PIN)){}; samplingEnd = micros(); // restore timer registers TCNT1 = TCNT1_b; TCCR1B = TCCR1B_b; TCCR1A = TCCR1A_b; TIMSK1 = TIMSK1_b; }
  • Node with Interrupt, sleep and batteries

    Troubleshooting interrupt sleep
    16
    0 Votes
    16 Posts
    11k Views
    sundberg84S
    Yea, now I understand how to use that!! I will do that, thats probably the best... will try! Thanks alot everybody involved! @martinhjelmare @AWI @Yveaux
  • Using more then 2 interrups on arduino

    Troubleshooting interrupt
    5
    0 Votes
    5 Posts
    3k Views
    B
    THx for the feedback. Now I can start to build my two pulse meters. One for my electricity usages and one for my natural gas usages. Bert
  • 0 Votes
    10 Posts
    6k Views
    hekH
    @dias I want a code with 2 relays and 2 pir You got to get started coding then :) If you bump into problem you can ask questions here.
  • using 2 interrupt pins (2,3) inside a node.

    Development interrupt pins
    3
    0 Votes
    3 Posts
    2k Views
    M
    ooouuu sorry missed that....(you really thought on everything with this library....)
  • Using Pin Change Interrupt (PCINT) for wakeup

    Development interrupt arduino
    6
    0 Votes
    6 Posts
    8k Views
    hekH
    Or use development branch where this dependency has been removed from the library.
  • 0 Votes
    4 Posts
    4k Views
    V
    I built a trip wire for the post box that I'm connecting. It's however based on a mercury tilt sensor so I'm really not sure whether I think it's a great idea putting it to use (at least not with a sturdy case...). However, I can share my code: #define DIGITAL_INPUT_SENSOR 2 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) MyMessage msgTripped(CHILD_ID_TRIPPED, V_TRIPPED); void setup() { gw.sendSketchInfo("Postal", "1.0"); gw.present(CHILD_ID_TRIPPED, S_MOTION); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input } void loop() { boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == LOW; if(tripped) { gw.send(msgTripped.set("1")); // Send tripped value to gw } gw.sleep(INTERRUPT,FALLING, SLEEP_TIME); }
  • 0 Votes
    28 Posts
    21k Views
    Paul AugustoP
    2 part video showing how to tie the TP4056 and MAX17043 boards together and to an arduino pro mini. Part 1: https://www.youtube.com/watch?v=3yHRrPDczK4 Part 2: https://www.youtube.com/watch?v=ZtkIDwkrc6E
  • Interrupt on recieve radio data

    Hardware interrupt battery powered
    14
    0 Votes
    14 Posts
    10k Views
    hekH
    @jonnyfishman said: would it be better to trigger the callback manually to pick up a response? No that won't help (as long as you call gw.process() ).

11

Online

11.7k

Users

11.2k

Topics

113.1k

Posts