Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions C_C++/lilka_modules/lora_beacon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
LoRa-маяк (модуль 003 LORA)
===========================

Кожні 10 секунд надсилає пакет `LILKA #N` на 868.1 МГц і виводить у послідовний порт усі прийняті пакети
(RSSI, SNR). Використовує драйвер `lilka::mod::SX126x` з бібліотеки `LilkaModules`.

Контакти модуля беруться з `lilka::config` (секція `[lora]`); змінити їх можна файлом у `/sd/.lilka/config/`.

```sh
pio run -t upload && pio device monitor
```

Перевірте, які частоти й потужності дозволені у вашій країні, і не вмикайте передачу без антени.
10 changes: 10 additions & 0 deletions C_C++/lilka_modules/lora_beacon/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; LoRa-маяк для модуля 003 LORA (E22-900M, SX1262).
; Докладніше про конфігурацію PlatformIO: https://docs.platformio.org/en/latest/projectconf/index.html

[env:default]
platform = espressif32 @ ^6.6.0
board = lilka_v2
framework = arduino
lib_deps =
lilka/Lilka
lilka/LilkaModules
38 changes: 38 additions & 0 deletions C_C++/lilka_modules/lora_beacon/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Sends a LoRa beacon every 10 s and prints received packets (003 LORA module, E22-900M).
#include <lilka.h>
#include <lilka_modules.h>

using namespace lilka::mod;

SX126x radio;

void setup() {
lilka::begin();
// Pins come from lilka::config: built-in v2 values, overridable in /sd/.lilka/config/*.ini ([lora] ...)
lilka::SPI2.begin(pins::get("lora", "sck"), pins::get("lora", "miso"), pins::get("lora", "mosi"));
SX126x::Config cfg; // nss, busy, nrst, rxen, txen are read from [lora] too
cfg.spi = &lilka::SPI2;
cfg.frequencyHz = 868100000; // check what is allowed where you are
cfg.powerDbm = 0;
if (radio.begin(cfg) != SX126x::Result::OK) {
Serial.println("No SX126x found");
return;
}
radio.startReceive();
}

void loop() {
static uint32_t lastTx = 0;
static uint32_t counter = 0;
SX126x::Packet packet;
if (radio.receive(packet)) {
Serial.printf("RX %.*s rssi=%.1f snr=%.1f\n", packet.length, (const char*)packet.data, packet.rssi, packet.snr);
}
if (millis() - lastTx > 10000) {
char msg[32];
int n = snprintf(msg, sizeof(msg), "LILKA #%lu", (unsigned long)counter++);
radio.send(reinterpret_cast<const uint8_t*>(msg), n);
lastTx = millis();
}
vTaskDelay(pdMS_TO_TICKS(5));
}
25 changes: 25 additions & 0 deletions LUA/modules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Модулі розширення Лілки v2

Lua-приклади для [модулів розширення](https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/modules/) (потрібна Keira з модулями `gps`, `can`, `ir`, `lora`, `nrf24`, `cc1101`, `imu`, `mag`).

| Файл | Модуль | Що робить |
|---|---|---|
| [`gps.lua`](gps.lua) | 005 GPS | координати, висота, кількість супутників |
| [`can.lua`](can.lua) | 008 CAN | сніфер шини (режим `listen`, нічого не передає) |
| [`ir.lua`](ir.lua) | 002 IR | приймає сигнал пульта і повторює його кнопкою A |
| [`lora.lua`](lora.lua) | 003 LORA | чат між двома Лілками |
| [`nrf24.lua`](nrf24.lua) | 004 RF (nRF24L01+) | сканер діапазону 2.4 ГГц |
| [`cc1101.lua`](cc1101.lua) | 004 RF (CC1101) | індикатор сигналу на 433.92 МГц |
| [`imu.lua`](imu.lua) | 006 GYRO MAGNET | акселерометр і гіроскоп |
| [`mag.lua`](mag.lua) | 006 GYRO MAGNET | компас з калібруванням |

Контакти модулів беруться з налаштувань Лілки; щоб змінити їх, покладіть INI-файл у `/sd/.lilka/config/`,
наприклад:

```ini
; /sd/.lilka/config/modules.ini
[lora]
nss = 21
```

Радіомодулі передають у ефір: під'єднайте антену і перевірте, які частоти й потужності дозволені у вашій країні.
19 changes: 19 additions & 0 deletions LUA/modules/can.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--[[
CAN-сніфер (модуль 008 CAN)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/can/
Керування: B - вихід
--]]

local bus = assert(can.new({bitrate = 500000, mode = "listen"}))

function lilka.update(delta)
local msg = bus:receive()
while msg do
local hex = msg.data:gsub(".", function(c) return string.format("%02X ", c:byte()) end)
console.print(string.format("%03X [%d] %s", msg.id, msg.dlc, hex))
msg = bus:receive()
end
if controller.get_state().b.just_pressed then
util.exit()
end
end
21 changes: 21 additions & 0 deletions LUA/modules/cc1101.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--[[
Індикатор сигналу 433.92 МГц (модуль 004 RF, CC1101)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/cc1101/
Керування: B - вихід
--]]

local radio = assert(cc1101.new({frequency = 433.92}))

function lilka.update(delta)
if controller.get_state().b.just_pressed then
util.exit()
end
end

function lilka.draw()
local rssi = radio:rssi()
display.fill_screen(display.color565(0, 0, 0))
display.set_cursor(10, 40)
display.print(string.format("%.1f dBm", rssi))
display.fill_rect(10, 80, math.max(0, (rssi + 110) * 3), 20, display.color565(255, 128, 0))
end
27 changes: 27 additions & 0 deletions LUA/modules/gps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--[[
GPS: координати і супутники (модуль 005 GPS)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/gps/
Керування: B - вихід
--]]

local receiver = assert(gps.new())

function lilka.update(delta)
receiver:update()
if controller.get_state().b.just_pressed then
receiver:close()
util.exit()
end
end

function lilka.draw()
local fix = receiver:fix()
display.fill_screen(display.color565(0, 0, 0))
display.set_cursor(10, 40)
if fix.valid then
display.print(string.format("%.5f %.5f\n%.0f m, %d sat", fix.latitude, fix.longitude,
fix.altitude, fix.satellites))
else
display.print("Шукаю супутники: " .. #receiver:satellites())
end
end
22 changes: 22 additions & 0 deletions LUA/modules/imu.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--[[
Акселерометр і гіроскоп (модуль 006 GYRO MAGNET, BMI260)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/imu/
Керування: B - вихід
--]]

local sensor = assert(imu.new())

function lilka.update(delta)
if controller.get_state().b.just_pressed then
util.exit()
end
end

function lilka.draw()
local d = sensor:read()
display.fill_screen(display.color565(0, 0, 0))
display.set_cursor(10, 40)
if d then
display.print(string.format("a: %.2f %.2f %.2f g\ng: %.1f %.1f %.1f", d.ax, d.ay, d.az, d.gx, d.gy, d.gz))
end
end
33 changes: 33 additions & 0 deletions LUA/modules/ir.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--[[
Навчити й повторити ІЧ-пульт (модуль 002 IR)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/ir/
Керування: A - повторити вивчений сигнал, B - вихід
--]]

local remote = assert(ir.new())
local learned = nil

function lilka.update(delta)
local code = remote:receive()
if code and not code["repeat"] then
learned = code
end
local state = controller.get_state()
if state.a.just_pressed and learned then
remote:send_raw(learned.raw)
end
if state.b.just_pressed then
util.exit()
end
end

function lilka.draw()
display.fill_screen(display.color565(0, 0, 0))
display.set_cursor(10, 40)
if learned then
display.print(string.format("%s 0x%X 0x%X\nA - повторити", learned.protocol,
learned.address or 0, learned.command or 0))
else
display.print("Натисніть кнопку на пульті")
end
end
28 changes: 28 additions & 0 deletions LUA/modules/lora.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--[[
LoRa-чат між двома Лілками (модуль 003 LORA)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/lora/
Керування: A - надіслати, B - вихід
--]]

local radio = assert(lora.new({chip = "sx1262", frequency = 868100000, sf = 7}))
local last = "-"

function lilka.update(delta)
local packet = radio:receive()
if packet then
last = string.format("%s (%.0f dBm, SNR %.1f)", packet.data, packet.rssi, packet.snr)
end
local state = controller.get_state()
if state.a.just_pressed then
radio:send("Привіт від Лілки!")
end
if state.b.just_pressed then
util.exit()
end
end

function lilka.draw()
display.fill_screen(display.color565(0, 0, 0))
display.set_cursor(10, 40)
display.print("A - надіслати\n" .. last)
end
27 changes: 27 additions & 0 deletions LUA/modules/mag.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--[[
Компас з калібруванням (модуль 006 GYRO MAGNET, TMAG5273)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/mag/
Керування: A - почати/завершити калібрування, B - вихід
--]]

local sensor = assert(mag.new())
local calibrating = false

function lilka.update(delta)
local state = controller.get_state()
if state.a.just_pressed then
calibrating = not calibrating
if calibrating then sensor:start_calibration() else sensor:stop_calibration() end
end
if state.b.just_pressed then
util.exit()
end
end

function lilka.draw()
local heading = sensor:heading()
display.fill_screen(display.color565(0, 0, 0))
display.set_cursor(10, 40)
display.print(calibrating and "Обертайте Лілку...\nA - готово" or
string.format("%.0f°\nA - калібрування", heading or 0))
end
23 changes: 23 additions & 0 deletions LUA/modules/nrf24.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--[[
Сканер діапазону 2.4 ГГц (модуль 004 RF, nRF24L01+)
Документація: https://docs.lilka.dev/projects/keira/uk/latest/lua/reference/nrf24/
Керування: B - вихід
--]]

local radio = assert(nrf24.new())
local hits = {}

function lilka.update(delta)
hits = radio:scan(2)
if controller.get_state().b.just_pressed then
util.exit()
end
end

function lilka.draw()
display.fill_screen(display.color565(0, 0, 0))
for ch = 1, #hits do
local h = hits[ch] * 40
display.fill_rect(10 + ch * 2, 200 - h, 2, h, display.color565(0, 255, 0))
end
end