Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino IDE compatible #3

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
61d6a2a
Rename file to folder name and change main file extension to .ino
latchdevel Mar 28, 2021
86d5757
Set VERSION to 2 and add a license mention
latchdevel Mar 28, 2021
f296165
First functional build with Arduino IDE that includes "wiring.c"
latchdevel Mar 28, 2021
9d78816
Change serial UART init and RX interrupt hander to Arduino style.
latchdevel Mar 29, 2021
e0f0db9
Change serial UART TX to Arduino style
latchdevel Mar 29, 2021
0b8c7e7
Change RF RX ISR to Arduino style configurable pin
latchdevel Mar 29, 2021
d7a8053
Change RF TX output to Arduino style configurable pin
latchdevel Mar 29, 2021
1aa73e7
Remove power save settings
latchdevel Mar 29, 2021
9640a07
Initialize plstypes array to zero at declare time
latchdevel Mar 29, 2021
712f073
Replaces 10us custom Timer2 ticks to standard Arduino micros() function
latchdevel Mar 29, 2021
8f4dc38
Adds all boards support
latchdevel Mar 29, 2021
7ca2160
Update Readme file
latchdevel Mar 29, 2021
3ec280c
Remove redundant includes
latchdevel Mar 30, 2021
65e6bc0
Remove global vars codelen and repeats
latchdevel Mar 30, 2021
41452c2
Remove unused vars
latchdevel Mar 30, 2021
849b67d
Add precompiler option to include stripped spaces
latchdevel Mar 30, 2021
f13b236
Move broadcast() to loop()
latchdevel Mar 30, 2021
dd13b77
Move receive() to loop()
latchdevel Mar 30, 2021
07d2e64
Add support to led blink on valid RX
latchdevel Mar 30, 2021
fa63ecd
Add support to sets valid RX settings at boot
latchdevel Mar 30, 2021
9ee31d1
Update Readme.md
latchdevel Mar 30, 2021
0e44e7d
Fix compiler warnings, and others cosmetics
latchdevel Mar 31, 2021
dd65006
Add "Compile tests" GitHub Action
latchdevel Mar 31, 2021
bc7e90f
Add compile tests action status badge
latchdevel Mar 31, 2021
5066648
Add support to configure show settings at boot
latchdevel May 3, 2021
6ace4c1
Support to configure add line feed '\n' each line output
latchdevel May 3, 2021
c3ea2be
Fix MIN/MAX PULSELENGTH values and their display
latchdevel May 9, 2021
33faa0c
Fix type size of plstypes from int16_t to int32_t
latchdevel May 9, 2021
8e803a9
Add maxgaplen check, and improve long pulses accuracy
latchdevel May 10, 2021
04a9a06
Add maxgaplen check also in RX, and clear buffer in TX
latchdevel May 15, 2021
0316341
Optimize size of maxgaplen from uint32_t to unit16_t
May 19, 2021
f5c19c7
Optimize size of mingaplen from uint32_t to unit16_t
May 19, 2021
771c4df
Optimize size of minrawlen and maxrawlen from uint32_t to uint8_t
May 19, 2021
f9d1fd5
Increased mingaplen because Maclean protocol (ELECTRO DH 60.531/M) ha…
May 19, 2021
638a211
Remove interrupt management for better RX
May 19, 2021
6ff047f
Tune MIN_PULSELENGTH to 6, for 100 usec minimal pulse
May 20, 2021
0bde571
Reduce MAX_PULSELENGTH to maxgaplen initial setting
May 20, 2021
f885f2f
Update .gitignore file
latchdevel Sep 5, 2021
4d20d83
Add support to configure a tx enable pin (PTT_PIN)
latchdevel Sep 5, 2021
a96f2e3
Fix serialEvent() ISR call unimplemented
latchdevel Sep 23, 2021
1b20d45
Fix ISR_RX() ram attribute on ESP8266 and ESP32
latchdevel Sep 26, 2021
ee6fe2d
Add Compile Test for ESP32 platform
latchdevel Sep 26, 2021
6579e79
Change --warnings from 'all' to 'none'
latchdevel Sep 26, 2021
2285843
Update action versions
latchdevel Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/CompileTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# This is the name of the workflow, visible on GitHub UI.
name: 'Compile tests'

#description: 'Run the Arduino CLI to compile the sketch and check if it compiles fine for multiple boards'
#author: 'Jorge Rivera'

# Controls when the action will run.
# Here we tell GitHub to run the workflow when a commit.
on:
# Triggers the workflow on push or pull request events but only for the "arduino" branch
push:
branches: [ arduino ]
paths:
- '*.ino'
- '.github/workflows/*.yml'

pull_request:
branches: [ arduino ]
paths:
- '*.ino'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# This is the list of jobs that will be run concurrently.
# Since we use a build matrix, the actual number of jobs
# started depends on how many configurations the matrix
# will produce.
jobs:
boards:

# This is the name of the job
name: "Compile test for ${{ matrix.config.board }}"

# This is the platform GitHub will use to run our workflow, we
# pick Linux for no particular reason.
runs-on: ubuntu-latest

# Here we tell GitHub that the jobs must be determined
# dynamically depending on a matrix configuration.
strategy:

# Set to false so that GitHub does not cancel all jobs
# in progress if any array job fails.
fail-fast: false

# The matrix will produce one job for each configuration:
matrix:
config:
- board: "Arduino Nano"
fqbn: "arduino:avr:nano"
platform: "arduino:avr"

- board: "Arduino UNO"
fqbn: "arduino:avr:uno"
platform: "arduino:avr"

- board: "Arduino Leonardo"
fqbn: "arduino:avr:leonardo"
platform: "arduino:avr"

- board: "Arduino Due (Native USB Port)"
fqbn: "arduino:sam:arduino_due_x"
platform: "arduino:sam"

- board: "Arduino M0"
fqbn: "arduino:samd:mzero_bl"
platform: "arduino:samd"

- board: "ESP8266 NodeMCUv2"
fqbn: "esp8266:esp8266:nodemcuv2"
platform: "esp8266:esp8266"
additional-url: "--additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json"

- board: "ESP32 NodeMCU-32S"
fqbn: "esp32:esp32:nodemcu-32s"
platform: "esp32:esp32"
additional-url: "--additional-urls https://dl.espressif.com/dl/package_esp32_index.json"

# This is the list of steps this job will run.
steps:
# First of all, we clone the repo using the "checkout" action.
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v4

# We use the "arduino/setup-arduino-cli" action to install and
# configure the Arduino CLI on the system.
- name: Setup Arduino CLI
uses: arduino/setup-arduino-cli@v2

# We then install the platform, which one will be determined
# dynamically by the build matrix.
- name: Install platform ${{ matrix.config.platform }}
run: |
arduino-cli config init -v ${{ matrix.config.additional-url }}
arduino-cli core update-index -v
arduino-cli core install -v ${{ matrix.config.platform }} --run-post-install

# Finally, we compile the sketch, using the FQBN that was set in the build matrix.
- name: Compile sketch for ${{ matrix.config.board }}
run: arduino-cli compile -v --fqbn ${{ matrix.config.fqbn }} --export-binaries --warnings none --log-level info

# Upload binary (.hex) files to artifacts
- name: Upload compiled binaries files to Artifacts
uses: actions/upload-artifact@v4
with:
name: "Binaries for ${{ matrix.config.board }}"
path: ./
29 changes: 28 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
# Compiler outputs
build/*

# Visual Studio Code
.vscode/
*.code-workspace
.history/

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Thumbs.db

# Prerequisites
*.d

# Precompiled Headers
*.gch
*.pch

# Object files
*.o
*.ko
*.obj
*.elf
*.bin
*.eep
*.lo
*.slo

# Precompiled Headers
*.gch
Expand All @@ -12,7 +39,7 @@
*.lib
*.a
*.la
*.lo
*.lai

# Shared objects (inc. Windows DLLs)
*.dll
Expand Down
125 changes: 108 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,127 @@
# pilight USB Nano
# pilight USB Nano v2 (Arduino compatible)

The pilight Arduino Nano software allows any computer with an USB port to work with pilight.
The pilight USB Nano software allows any computer with an USB port to work with pilight.

[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0)
[![Compile tests](https://github.com/latchdevel/pilight-usb-nano/actions/workflows/CompileTests.yml/badge.svg?branch=arduino)](https://github.com/latchdevel/pilight-usb-nano/actions/workflows/CompileTests.yml)

## New v2 firmware features:
- Can run on any AVR Arduino compatible board, like Arduino UNO, Nano, MEGA, Leonardo, etc. any clock speed allowed.
- Can run on other platforms like Arduino SAMD boards (DUE, M0, etc.), ESP8266, ESP32, Teensy, even Raspberry Pico.
- Works using the MCU's internal USB-Serial COM port (CDC/ACM device class) or any onboard/external USB-Serial adapter.
- Fully Arduino IDE compiler environment compatible. Arduino PRO IDE and Arduino CLI also supported.
- Configurable RF receiver output (RX_PIN); must be interrupt attachable, depends board (D2 as default).
- Configurable RF transmitter input (TX_PIN); can be any digital pin, depends board (D5 as default).
- Support to configure a digital output so that a led blinks at valid RF code reception.
- Support to configure send of every 'space' before 'pulse', which stripped in previous version firmware.
- Support to configure initial RX settings at boot, like as 's:22,200,3000,51000@'.
- Support to configure show settings at boot, like as: 'v:20,200,4000,82000,2,1,1600@'.
- Support to configure add line feed '\n' each line output.
- Support to configure a tx enable pin (PTT_PIN), useful for use transceivers.
- Fix TX pulse generator drift from 9.95µS to 0.69µS (AVR@16Mhz).
- Improve RX pulse meter resolution from 10µS to 4µS (AVR@16Mhz).

## Usage:

1. Compile the firmware:
```
avr-gcc -Os -Wall -DF_CPU=16000000UL -mmcu=atmega328p -c -o pilight_usb_nano.o pilight_usb_nano.c -lm -I.
avr-gcc -mmcu=atmega328p pilight_usb_nano.o -o pilight_usb_nano
avr-objcopy -O ihex -R .eeprom pilight_usb_nano pilight_usb_nano.hex
```
2. Flash the firmware on the Arduino Nano:
`avrdude -b 57600 -p atmega328p -c arduino -P COM5 -U flash:w:pilight_usb_nano.hex`
3. Connect the receiver data pin to D2 and the sender to D5.
4. Connect the Arduino Nano to your computer.
5. Check what COM port the Arduino Nano is using.
6. Configure pilight to interface with the Arduino Nano (see below).
```
- Open Arduino IDE application
- File> Open> Select file "pilight-usb-nano.ino"
- Tools> Board> Select your board
- Sketch> Verify/Compile
```
2. Flash the firmware on the board:
```
- Tools> Port> Select your USB/Serial COM port
- Sketch> Upload
```
3. Connect the receiver data pin to configured RX_PIN (D2 as default) and the transmitter data pin to configured TX_PIN (D5 as default).
4. Connect the Arduino to your computer.
5. Check what Serial/COM port the Arduino is using.
6. Configure pilight to interface with the Arduino (see below).
7. Start pilight normally and it should work OOTB.

pilight USB nano hardware configuration:
## pilight USB Arduino hardware configuration:

Linux example:
```
```json
"hardware": {
"433nano": {
"comport": "/dev/ttyUSB0"
}
}
```
Windows Example:
```
```json
"hardware": {
"433nano": {
"comport": "COM5"
}
}
```
```

## Example:
Transmitter code:
```
c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800;r:4@
```
* Receive with spaces:
```
c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@
```

* Receive without spaces:
```
c:100011100010001010111010000000002;p:1400,600,6800@
```

## Decoding:
You can decode and encode any code using an external tool **"picoder"** from https://github.com/latchdevel/picoder

Decode example:
```
$ picoder decode -s "c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@"
```
return:
```json
[{
"conrad_rsl_switch": {
"id": 1,
"unit": 2,
"state": "on"
}
}]
```

Encode example:
```json
$ picoder encode -f '{ "conrad_rsl_switch" : {"id":1,"unit":2,"on":1} }' -r 5
```
return:
```
c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800;r:5@
```

## To do:
- [ ] Support to measure RSSI of receivers that provide it.

# License

Copyright (C) 2015 CurlyMo. This file is part of pilight. GPLv3.

Copyright (C) 2021 Jorge Rivera. GNU General Public License v3.0.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.


Loading