Skip to content

Instantly share code, notes, and snippets.

View rosmianto's full-sized avatar
🏠
Working from home

Rosmianto Saputro rosmianto

🏠
Working from home
View GitHub Profile
@rosmianto
rosmianto / STM32_I2C_Scanner.c
Created October 12, 2021 12:17
Snippet to scan connected I2C slaves
#if 1
uint8_t status[128] = {};
for (int i = 1; i < 128; i++) {
HAL_StatusTypeDef ret = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 3, 5);
if (ret != HAL_OK) /* No ACK Received At That Address */
{
status[i] = 0;
}
else if(ret == HAL_OK)
@rosmianto
rosmianto / list_sdcard.ino
Created February 23, 2020 06:59
How to List SD Card directory content Arduino Platform
Serial.println("List dir");
File root = SD.open("/");
File file = root.openNextFile();
while (file) {
Serial.print("FILE: ");
Serial.println(file.name());
file = root.openNextFile();
}
Serial.println("opening...");
@rosmianto
rosmianto / resettable_eeprom.ino
Created February 23, 2020 06:57
Implementation of Resettable EEPROM config using external button Arduino Platform
/*
IoT.ino -- Example code for demonstration only.
Written by Rosmianto A. Saputro. Aug 25, 2017.
To do list:
* Implement OTA
* Implement Server/client code.
* Implement EEPROM update code.
*/
@rosmianto
rosmianto / convert_byte_array.ino
Created February 23, 2020 06:56
How to Convert Byte Array to Hexstring Arduino Platform
void setup() {
byte example[] = {0x31, 0x32, 0x33, 0x34};
int length = 4;
String result = "";
String hexstring = "";
for(int i = 0; i < length; i++) {
if(example[i] < 0x10) {
hexstring += '0';
@rosmianto
rosmianto / 4mhz_clock.ino
Created February 23, 2020 06:54
How to Generate 4MHz clock with Arduino Uno
void setup() {
// put your setup code here, to run once:
TCNT1 = 0;
TCCR1B = B00001001;
TCCR1A = B01000000;
OCR1A = 1; // CLK frequency = 4 MHz
pinMode(9, OUTPUT);
}
void loop() {