Skip to content

Instantly share code, notes, and snippets.

View reefwing's full-sized avatar

David Such reefwing

View GitHub Profile
@reefwing
reefwing / SSD1306AsciiTest.ino
Created November 15, 2022 08:08
Test sketch for the SSD1306Ascii Library
#include <SPI.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiSoftSpi.h"
// pin definitions
#define MOSI 11
#define DC 12
#define SCK 13
#define CS 14
@reefwing
reefwing / u8g2Test.ino
Last active November 15, 2022 08:00
Test sketch for u8g2 Page Mode, Hardware SPI
#include <U8g2lib.h>
#include <SPI.h>
#define MOSI 11
#define DC 9
#define SCK 13
#define CS 10
#define SAMPLE_TIME 1000 // 1 second = 1000 ms
@reefwing
reefwing / oledTest.ino
Created November 15, 2022 00:42
Test 128x64 pixel OLED display using U8x8 Library
#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#define MOSI 11
#define DC 9
#define SCK 13
#define CS 14
@reefwing
reefwing / MMC5883MA_Demo.ino
Created October 14, 2022 07:16
Demo sketch to test the Duinotech 3 axis magnetometer
#include <Wire.h>
#include "MMC5883.h"
MMC5883MA MMC5883(Wire);
void setup() {
Serial.begin (115200);
Serial.println ("\nMMC5883MA Magnetometer Demo Sketch");
Wire.begin();
@reefwing
reefwing / MMC5883MA_Product_ID.ino
Created October 14, 2022 01:56
Arduino sketch to check the Product ID register of a MMC5883MA
#include <Wire.h>
#define MMC5883MA_ADDR 0x30
#define MMC5883MA_ID_REG 0x2F
#define MMC5883MA_ID 0x0C
void setup() {
Serial.begin (115200);
Serial.println ("\nMMC5883MA Magnetometer Check Sketch");
@reefwing
reefwing / armESC.ino
Created September 3, 2022 00:41
Arming ESC with BLHeli_S v16.7 firmware
void armESC() {
delay(3000);
ESC1.writeMicroseconds(QUARTER_PULSEWIDTH);
ESC2.writeMicroseconds(QUARTER_PULSEWIDTH);
ESC3.writeMicroseconds(QUARTER_PULSEWIDTH);
ESC4.writeMicroseconds(QUARTER_PULSEWIDTH);
delay(2000);
ESC1.writeMicroseconds(MIN_PULSEWIDTH);
ESC2.writeMicroseconds(MIN_PULSEWIDTH);
ESC3.writeMicroseconds(MIN_PULSEWIDTH);
@reefwing
reefwing / MotorDriver.ino
Created September 1, 2022 07:31
Arduino example driver sketch for H-bridge
1. /******************************************************************
2. @file MotorDriver.ino
3. @brief Drive two bi-directional motors using a H-bridge
4. ******************************************************************/
5.
6. #define M1_ENABLE 3
7. #define M1_INPUT1 2
8. #define M1_INPUT2 4
9.
10. #define M2_ENABLE 11
@reefwing
reefwing / Debug32.c
Created June 15, 2022 01:40
Structure from the NexgenMSP Arduino library
// MSP_DEBUGMSG Packet contents
struct msp_debug_msg_t {
char msg[32];
} __attribute__ ((packed));
@reefwing
reefwing / cast_payload.c
Created June 15, 2022 01:37
Example casting to char array
size_t structSize = sizeof(debug32);
strncpy(debug32.msg, "Payload Rx: ", 13);
strcat(debug32.msg, (const char*)payload);
msp.response(MSP_DEBUGMSG, &debug32, structSize);
@reefwing
reefwing / NexgenMSP_readPayload.cpp
Created June 14, 2022 06:57
Extract from the Nexgen MSP Arduino Library
// read payload
uint8_t * payloadPtr = (uint8_t*)payload;
uint8_t idx = 0;
while (idx < *recvSize) {
if (millis() - t0 >= _timeout)
return false;
if (_stream->available() > 0) {
uint8_t b = _stream->read();
checksumCalc ^= b;
if (idx < maxSize)