Trading Data between 2 chips running different programs?

David Presley

New Member
Hi,

The task at hand is collecting data, processing / displaying it locally at 1 minute intervals and then sending it to ThingSpeak at 15 minute intervals via an ESP-01.
Due to the fact the main control circuit is going to be in a metal box, I thought the wf-fi module might do better in a different location, about 3' away.

I can't figure out how to interrupt the main program at 15 minute intervals. Is there a way to write a subroutine that would do this, while still allowing the main code to continue with its' assignments?

If not, the idea was to have an 08M2 running in the 2nd location concurrently, driving the wi-fi module. At the 15 minute interval, it would get the readings from the main chip (14M2) and send the data on to ThingSpeak. From the i2c documentation, it doesn't seem possible for the 2nd (slave) device to run a program and be a slave. Am I wrong?

Any thoughts or suggestions are welcome.

Thanks.
 

AllyCat

Senior Member
Hi,

No, the M2 PICaxes do not support an I2C Slave mode, except by bit-banging your own code.

You haven't indicated the basic structure of your "main" 14M2 program and I'm not clear what initiates the 15 minutes Transmission Event, the ESP-01 or the/a PICaxe ? The ESP could interrupt the PICaxe, which would then need an appropriate Interrupt Service Routine (coded after an interrupt: label). Alternatively, if the PICaxe is required to "interrupt" itself every 15 minutes, then cannot the "one minute data processing" main loop simply increment a (software) counter and Branch to the Transmission Event software after each count of 15?

The M2s don't have a "Timer Interrupt" facility as such, so if you need a completely "independent" timed interrupt then you could connect a PWMOUT or SERVO output pulse to one of the Interrupt input pins (the 14M2 has three). Unfortunately, the lowest output pulse frequency is 50 Hz or more, so you would need a small/fast ISR to count each pulse and then Branch to the "main ISR function" after each count of around 50 * 60 * 15 = 45000 pulses (i.e. within the capacity of a Word variable).

Cheers, Alan.
 

lbenson

Senior Member
Pseudo-code:
Code:
do
  time=0
  do until time>900 ' for 15 minutes
    ' do stuff here
  loop
  serout [whatever you want the wifi unit to transmit with the ESP-01, maybe with checksum, ACK/NAK if needed]
loop
Receiving 08M2 sits in SERIN until it receives a transmission.
 

David Presley

New Member
Thanks, guys. Between your two responses, you had the answers I was looking for.
AllyCat, the code would initiate the event. To my knowledge, the ESP-01 doesn't have a timer. The counter for processing iterations will do the trick.
Best of all, it'll do it on one chip and eliminate the need for communication.
Ibenson, I think I'll be using a variation of your approach to implement it.
Again, thank you both.
 
Top