Skip to content

Instantly share code, notes, and snippets.

@rngtng
Last active August 13, 2020 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rngtng/3d5dbc2c5f45304d34140360d30a3078 to your computer and use it in GitHub Desktop.
Save rngtng/3d5dbc2c5f45304d34140360d30a3078 to your computer and use it in GitHub Desktop.
DASH Button OTA Standalone

I don't get DASH button with OTA ins standalone working. ASAP I add the pwr_en PIN the boot process stops. When I re-connect to creator pro (just GND & reset) it works.

Feels like the battery is to weak or sth?

#include <WiFi.h>
#include <OTA.h>
char ssid[] = "...";
char pass[] = "....";
char mDNS_NAME[] = "AmebaIoT";
#define FW_REV 4
#define FW_OTA_PORT 8888
#define LED1 0
#define LED2 1
#define LED3 2
#define LED4 3
#define RED 0
#define GREEN 1
#define BLUE 2
#define OFF 3
/* power enable */
int pwr_en = 15;
/* leds */
int led1_r = 25;
int led1_g = 24;
int led1_b = 19;
int led2_r = 0;
int led2_g = 2;
int led2_b = 6;
int led4_r = 12;
int led4_g = 11;
int led4_b = 13;
int led3_r = 22;
int led3_g = 21;
int led3_b = 1;
/* keys */
int key1 = 23;
int key2 = 14;
int key3 = 10;
int key4 = 20;
void setup() {
// Serial.begin(9600);
printf("Firmware revision version: %d\r\n", FW_REV);
// pinMode(pwr_en, OUTPUT);
// printf("pwr init \r\n");
// digitalWrite(pwr_en, 1);
// printf("pwr set \r\n");
pinMode(led1_r, OUTPUT);
pinMode(led1_g, OUTPUT);
pinMode(led1_b, OUTPUT);
printf("led1 init \r\n");
pinMode(led2_r, OUTPUT);
pinMode(led2_g, OUTPUT);
pinMode(led2_b, OUTPUT);
printf("led2 init \r\n");
pinMode(led3_r, OUTPUT);
pinMode(led3_g, OUTPUT);
pinMode(led3_b, OUTPUT);
printf("led3 init \r\n");
pinMode(led4_r, OUTPUT);
pinMode(led4_g, OUTPUT);
pinMode(led4_b, OUTPUT);
printf("led4 init \r\n");
pinMode(key1, INPUT_PULLUP);
pinMode(key2, INPUT_PULLUP);
pinMode(key3, INPUT_PULLUP);
pinMode(key4, INPUT_PULLUP);
printf("key init \r\n");
// pinMode(led4_g, OUTPUT);
// pinMode(led4_r, OUTPUT);
// pinMode(led1_g, OUTPUT);
// pinMode(led1_r, OUTPUT);
// pinMode(key1, INPUT_PULLUP);
printf("Connecting to %s\r\n\r\n", ssid);
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
printf("Couldnt connect to ssid...\r\n");
delay(1000);
}
printf("\r\nSuccessfully Connected to %s\r\n", ssid);
led_ctrl(LED1, OFF);
led_ctrl(LED2, OFF);
led_ctrl(LED3, OFF);
led_ctrl(LED4, OFF);
}
void loop() {
led_ctrl(LED2, GREEN);
led_ctrl(LED3, GREEN);
led_ctrl(LED1, OFF);
led_ctrl(LED4, OFF);
delay(500);
led_ctrl(LED2, OFF);
led_ctrl(LED3, OFF);
led_ctrl(LED1, RED);
led_ctrl(LED4, RED);
delay(500);
if (digitalRead(key2) == 0) {
led_ctrl(LED1, RED);
led_ctrl(LED2, RED);
led_ctrl(LED3, RED);
led_ctrl(LED4, RED);
OTA.beginArduinoMdnsService(mDNS_NAME, FW_OTA_PORT);
if (OTA.beginLocal(FW_OTA_PORT) < 0) {
printf("OTA firmware upload failed!!\r\n");
}
}
if (digitalRead(key3) == 0) {
int battery = 0, i = 0;
for (i = 0; i < 10; i++) {
battery = analogRead(A2);
printf("Battery %d\r\n", battery);
delay(10);
}
}
}
void led_ctrl(uint8_t led_num, uint8_t rgb)
{
switch (led_num) {
case LED1:
if (rgb == RED) {
digitalWrite(led1_r, 0);
digitalWrite(led1_g, 1);
digitalWrite(led1_b, 1);
}
else if (rgb == GREEN) {
digitalWrite(led1_r, 1);
digitalWrite(led1_g, 0);
digitalWrite(led1_b, 1);
}
else if (rgb == BLUE) {
digitalWrite(led1_r, 1);
digitalWrite(led1_g, 1);
digitalWrite(led1_b, 0);
}
else if (rgb == OFF) {
digitalWrite(led1_r, 1);
digitalWrite(led1_g, 1);
digitalWrite(led1_b, 1);
}
break;
case LED2:
if (rgb == RED) {
digitalWrite(led2_r, 0);
digitalWrite(led2_g, 1);
digitalWrite(led2_b, 1);
}
else if (rgb == GREEN) {
digitalWrite(led2_r, 1);
digitalWrite(led2_g, 0);
digitalWrite(led2_b, 1);
}
else if (rgb == BLUE) {
digitalWrite(led2_r, 1);
digitalWrite(led2_g, 1);
digitalWrite(led2_b, 0);
}
else if (rgb == OFF) {
digitalWrite(led2_r, 1);
digitalWrite(led2_g, 1);
digitalWrite(led2_b, 1);
}
break;
case LED3:
if (rgb == RED) {
digitalWrite(led3_r, 0);
digitalWrite(led3_g, 1);
digitalWrite(led3_b, 1);
}
else if (rgb == GREEN) {
digitalWrite(led3_r, 1);
digitalWrite(led3_g, 0);
digitalWrite(led3_b, 1);
}
else if (rgb == BLUE) {
digitalWrite(led3_r, 1);
digitalWrite(led3_g, 1);
digitalWrite(led3_b, 0);
}
else if (rgb == OFF) {
digitalWrite(led3_r, 1);
digitalWrite(led3_g, 1);
digitalWrite(led3_b, 1);
}
break;
case LED4:
if (rgb == RED) {
digitalWrite(led4_r, 0);
digitalWrite(led4_g, 1);
digitalWrite(led4_b, 1);
}
else if (rgb == GREEN) {
digitalWrite(led4_r, 1);
digitalWrite(led4_g, 0);
digitalWrite(led4_b, 1);
}
else if (rgb == BLUE) {
digitalWrite(led4_r, 1);
digitalWrite(led4_g, 1);
digitalWrite(led4_b, 0);
}
else if (rgb == OFF) {
digitalWrite(led4_r, 1);
digitalWrite(led4_g, 1);
digitalWrite(led4_b, 1);
}
break;
default:
break;
}
}
/*
Author Naresh Krish
This arduino program shows how to update AmebaIOT image via Arduino IDE.
1) Upload the sketch to the creator pro baord for the first time and Reset the board Ameba.
2) Part of the code starts an mdns service called " MyAmeba". Ideally the version of sketc is version 1
3) Now edit this sketch. (Ex. the version number) and then reupload, this time instead of choosing USB port,
use the IP based port that will show up in the port meny in the arduino IDE
4) Once done Ameba would reboot. Check the serial port for the changes (eg version).
*/
#include <WiFi.h>
#include <OTA.h>
char ssid[] = "...";
char pass[] = "...";
char mDNS_NAME[] = "AmebaIoT";
#define FW_REV 1
#define FW_OTA_PORT 8888
/**
Here we define the recovery pins for the board
for the 8195/8711 its 18 and and for 8710 its 17
*/
#if defined(BOARD_RTL8195A)
#define RECOVER_PIN 18
#elif defined(BOARD_RTL8710)
#define RECOVER_PIN 17
#else
#define RECOVER_PIN 18
#endif
void setup() {
Serial.begin(9600);
//set the mdns name for the board to publish here.
//output the version number of the firmware here:
printf("Firmware revision version: %d\r\n", FW_REV);
printf("Connect to %s\r\n\r\n", ssid);
//wait for wifi to get connected to the access point you specifi
while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
printf("Couldnt connect to ssid...\r\n");
//wait for a second before retrying...
delay(1000);
}
//if connected print the success....
printf("\r\nSuccessfully Connected to %s\r\n", ssid);
// These setting are mostly one time setting. We dont need it to be built into the future versions code
// Set the recovery pin .
//Boot device with pull up this pin (Eq. connect pin to 3.3V) to recover to firmware rev 1 (forctory firmware)
OTA.setRecoverPin(RECOVER_PIN);
// This set the flash address that store the OTA image.
// Default value is DEFAULT_OTA_ADDRESS
OTA.setOtaAddress(DEFAULT_OTA_ADDRESS);
// Broadcast mDNS service at OTA_PORT that makes Arduino IDE find Ameba device
OTA.beginArduinoMdnsService(mDNS_NAME, FW_OTA_PORT);
// Listen at OTA_PORT and wait for client (Eq. Arduino IDE). Client would send OTA image and make a update.
if (OTA.beginLocal(FW_OTA_PORT) < 0) {
printf("OTA firmware upload failed!!\r\n");
}
}
void loop() {
}
=========================================================
ROM Version: 0.3
Build ToolChain Version: gcc version 4.8.3 (Realtek ASDK-4.8.3p1 Build 2003)
=========================================================
Check boot type form eFuse
SPI Initial
Image1 length: 0x3a88, Image Addr: 0x10000bc8
Image1 Validate OK, Going jump to Image1
BOOT from Flash:YES
===== Enter Image 1 ====
SDR Controller Init
load NEW fw 1
Flash Image2:Addr 0x80000, Len 191592, Load to SRAM 0x10006000
Image3 length: 0x17695, Image3 Addr: 0x30000000
Img2 Sign: RTKWin, InfaStart @ 0x10006049
===== Enter Image 2 ====
Firmware revision version: 4
[GPIO Err]HAL_GPIO_Init: GPIO Pin(44) Unavailable
led1 init
led2 init
led3 init
led4 init
key init
Connecting to g71
interface 0 is initialized
interface 1 is initialized
Initializing WIFI ...
WIFI initialized
RTL8195A[Driver]: set ssid [g71]
RTL8195A[Driver]: start auth to 34:31:c4:4d:ba:84
RTL8195A[Driver]: auth success, start assoc
RTL8195A[Driver]: association success(res=2)
RTL8195A[Driver]: set pairwise key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4)
RTL8195A[Driver]: set group key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4) keyid:2
Interface 0 IP address : 192.168.178.107
Successfully Connected to g71
RTL8195A[Driver]: set group key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4) keyid:1
=========================================================
ROM Version: 0.3
Build ToolChain Version: gcc version 4.8.3 (Realtek ASDK-4.8.3p1 Build 2003)
=========================================================
Check boot type form eFuse
SPI Initial
Image1 length: 0x3a88, Image Addr: 0x10000bc8
Image1 Validate OK, Going jump to Image1
BOOT from Flash:YES
===== Enter Image 1 ====
SDR Controller Init
load NEW fw 1
Flash Image2:Addr 0x80000, Len 191592, Load to SRAM 0x10006000
Image3 length: 0x17695, Image3 Addr: 0x30000000
Img2 Sign: RTKWin, InfaStart @ 0x10006049
===== Enter Image 2 ====
Firmware revision version: 4
@narioinc
Copy link

narioinc commented Dec 28, 2017

Hi,

As we discussed over @hackster i will look at the issue more closely and try to find why this would be the case. I have also emailed the RAK engineering team about the issue and lets see if they can also help us out here.

Regards
Naresh K

@RAKWireless
Copy link

Hi,

About dashbutton's reset issue. the dashbutton's reset pin need weld a wire and connect to the creator pro board's RESET pin, then you can
push creator pro board's reset key to reset dashbutton.
or you can use power up reset, connect every wire ok except dashbutton's vcc pin, lastly connect dashbutton's vcc to creator pro and watch
the serial log if reset ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment