Arduino Timer Protocol
OzTimer is a special countdown timer. It uses an 8 bit timer, wich is Timer 2 in both ATmega328P and ATmega2560 chips. Every tick increases a 64 bit global variable created in OzTimer.h. You can declare a lot of timers, because these are virtual timers based on the preciseness of Timer 2. You can set the initial value of the countdown timers to any year, day, hour, minute, second, millisecond and microsecond. It will start countdown immediately. The virtual timers will tick simultaneously. You can stop them all anytime. After any virtual timer finishes countdown it can run a predefined function that is added to the programcode.
How to test the OzTimer on Arduino Mega?
Arduino codes are included.
I. 'Welcome' event from microcontroller
Example
c=welcome&id=KT75pc&type=OzTimerController&pos=1&name=MyTimers&t=1
Parameters
Parameter | Type | Range | Functionality |
c | String | 'welcome' | Identifies the welcome message. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
type | String | 'OzTimer' | Determines the type of the devicehandler. |
pos | Byte | 0-255 | Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position. |
name (optional) | String | e.g. 'MyTimers' | You can give default names for devices. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
II. Commands to microcontroller
'Set status' command
Pauses or restarts the global timer. Timer 2 interrupts automatically increase the global timer. The virtual countdown timers use the global timer as reference.
Example
//Timer start c=setstatus&val=1&t=0&id=KT75pc
//Timer stop c=setstatus&val=0&t=1&id=KT75pc
Parameters
Parameter | Type | Range | Functionality |
c | String | 'setstatus' | Identifies the command. |
val | Bool | 0,1 | 0 pauses timers, 1 restarts them. |
t | Byte | 0-255 | Counts the number of commands and events sent combined. The 't' of the command is equal to the 't' of its response. Counts from 0 to 255 then from 0 again. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
Response
Returns if the global timer is turned on. The same response is for the 'status' command.
//Start timer response c=status_resp&val=1&id=KT75pc&t=2
//Stop timer response c=status_resp&val=0&id=KT75pc&t=3
Parameters
Parameter | Type | Range | Functionality |
c | String | 'status_resp' | Identifies the response. |
val | Bool | 0,1 | 0 means timers are paused. 1 means timers have been restarted. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'Status' command
Queries the status of the global timer.
Example
c=status&t=2&id=KT75pc
Parameters
Parameter | Type | Range | Functionality |
c | String | 'status' | Identifies the command. |
t | Byte | 0-255 | Counts the number of commands and events sent combined. The 't' of the command is equal to the 't' of its response. Counts from 0 to 255 then from 0 again. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
Response
Returns if global timer is turned on. The same response is for the 'setstatus' command.
c=status_resp&val=0&id=KT75pc&t=4
Parameters
Parameter | Type | Range | Functionality |
c | String | 'status_resp' | Identifies the response. |
val | Bool | 0,1 | 0 means the global timer is paused. 1 means the global timer is running. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'Elapsed' command
Asks the current value of the global timer which stores elapsed time in milliseconds.
Example
c=elapsed&t=3&id=KT75pc
Parameters
Parameter | Type | Range | Functionality |
c | String | 'elapsed' | Identifies the command. |
t | Byte | 0-255 | Counts the number of commands and events sent combined. The 't' of the command is equal to the 't' of its response. Counts from 0 to 255 then from 0 again. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
Response
Returns the current value of the global timer which stores elapsed time in milliseconds.
The global timer starts from the boot of the microcontroller.
c=elapsed_resp&val=229094&id=KT75pc&t=5
Parameters
Parameter | Type | Range | Functionality |
c | String | 'elapsed_resp' | Identifies the response. |
val | Unsigned Long | 0-232 | The time stored in the global timer. The time is stored in milliseconds. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
'Timers' command
Queries the status of every virtual timer. The virtual countdown timers use the global timer as reference.
Example
c=timers&t=4&id=KT75pc
Parameters
Parameter | Type | Range | Functionality |
c | String | 'timers' | Identifies the command. |
t | Byte | 0-255 | Counts the number of commands and events sent combined. The 't' of the command is equal to the 't' of its response. Counts from 0 to 255 then from 0 again. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
Response
You can see from the 'flag' parameter which countdown timer has reached 0.
//There are no active timers c=timers_resp&num=0&id=KT75pc&t=6
//There are some active timers c=timers_resp&owner=test_1&time=5000&flag=1&id=KT75pc&t=6 c=timers_resp&owner=test_2&time=6000&flag=0&id=KT75pc&t=7 [...]
Parameters
Parameter | Type | Range | Functionality |
c | String | 'timers_resp' | Identifies the response. |
num | Bool | Can only get 0 as value. | Parameter exists only if there are no active timers. |
owner | String | any ( e.g. test_1 ) | Actual timer's ID given in the ino file. |
time | Unsigned Long | 0-232 | It is NOT the remaining time left from the countdown. It is the initial value of the countdown timer in milliseconds (declared in the .ino file). |
flag | Bool | 0,1 | Flag which tells us whether the timer has expired or not. |
id | String | 6 characters (numbers, uppercase and lowercase characters) | The ID of the device which is chosen by the microcontroller. |
t | Byte | 0-255 | Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again. |
III. Event from microcontroller
None
More information
- RF 433 MHz Transceiver serial protocol
- Analog Joystick serial protocol
- Analog Sensor serial protocol
- Button serial protocol
- Buzzer serial protocol
- DC Motor serial protocol
- DHT Sensor serial protocol
- EEPROM serial protocol
- Keyboard serial protocol
- Gyroscope Sensor serial protocol
- ID Manager serial protocol
- IR Transceiver serial protocol
- LCD Display serial protocol
- NFC Reader serial protocol
- Optical Gate serial protocol
- Register
- RF24 Transceiver serial protocol
- RGB Led serial protocol
- RGB Sensor serial protocol
- Rotary Encoder serial protocol
- Servo Motor serial protocol
- Step Counter serial protocol
- Stepper Motor serial protocol
- Switch serial protocol
- Temperature Sensor serial protocol
- Timer serial protocol
- Ultrasonic Sensor serial protocol
- Welcome messages of the Ozeki 3D Printer