Skip to content

Commit d012f86

Browse files
committed
Clean up of examples
1 parent 85a7f61 commit d012f86

File tree

12 files changed

+269
-327
lines changed

12 files changed

+269
-327
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Author: Owen Lyke
2+
Created: May 2 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates how to use Arduino HardwareSerial class functions
6+
Uart objects inherit from HardwareSerial. Declare a Uart object with the following parameters:
7+
Uart myUart(instance, rx, tx, rts, cts)
8+
instance: either 0 or 1, corresponding to uart0 or uart1 in the Apollo3
9+
rx pin: (opt.) the *pin* number to use for rx. must map to a valid rx pad on the apollo3 for the uart instance
10+
tx pin: (opt.) the *pin* number to use for tx. must map to a valid tx pad on the apollo3 for the uart instance
11+
rts pin: (opt.) the *pin* number to use for rts. must map to a valid rts pad on the apollo3 for the uart instance
12+
cts pin: (opt.) the *pin* number to use for cts. must map to a valid cts pad on the apollo3 for the uart instance
13+
pin* means the variant's pin number, as opposed to the Apollo3 pad number. The provided number is mapped using the variant's pin map
14+
Use AP3_UART_PIN_UNUSED if a particular function is unnecessary
15+
Board-standard Uart objects can be declared in the variant configuration (variant.h and variant.cpp)
16+
17+
For example, this is the definition of Serial found in the SparkFun Edge variant
18+
Uart Serial(0, 49, 48);
19+
*/
20+
21+
#define SERIAL_PORT Serial
22+
23+
void setup() {
24+
25+
SERIAL_PORT.begin(115200);
26+
27+
while (!SERIAL_PORT) {}; // todo: right now this falls straight through
28+
29+
SERIAL_PORT.println("SparkFun Arduino Apollo3 Serial Example");
30+
SERIAL_PORT.printf("Compiled on %s, %s\n\n", __DATE__, __TIME__); // Look! You can use printf, if you so choose
31+
32+
SERIAL_PORT.print("Your Apollo3 variant has ");
33+
SERIAL_PORT.print(AP3_VARIANT_NUM_PINS);
34+
SERIAL_PORT.println(" pins.");
35+
SERIAL_PORT.println();
36+
}
37+
38+
void loop() {
39+
40+
if (SERIAL_PORT.available()) {
41+
while (SERIAL_PORT.available()) {
42+
char c = SERIAL_PORT.read();
43+
SERIAL_PORT.write(c);
44+
}
45+
}
46+
47+
}

libraries/CoreTesting/examples/Example7_analogRead/Example7_analogRead.ino

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
99
This example shows how to read an analog voltage from various ADC enabled pins.
1010
11+
Some boards have A0, A1, etc. Some boards have A23, A35, etc. Be sure to
12+
select the correct board from the boards menu and modify the code to match those pins.
13+
1114
Feel like supporting open source hardware?
1215
Buy a board from SparkFun!
1316
SparkFun Edge: https://www.sparkfun.com/products/15170
@@ -16,17 +19,15 @@
1619
Connect an Edge via programmer
1720
Upload code
1821
Use a trimpot or other device to send a 0 to 3V (no 5V!) signal to pin 'A16'
19-
Max reading on ADC is 2V
22+
ADC can resolve up to 2V but is 3.3V safe
2023
*/
2124

22-
#define LED 13 //Status LED
25+
#define LED 13 //Status LED on Artemis BlackBoard
2326

2427
void setup() {
2528
Serial.begin(9600);
2629
Serial.println("SparkFun Arduino Apollo3 Analog Read example");
2730

28-
delay(100);
29-
3031
pinMode(LED, OUTPUT);
3132

3233
//analogReadResolution(14); //Set resolution to 14 bit
@@ -37,49 +38,29 @@ void loop() {
3738
digitalWrite(LED, LOW);
3839

3940
int myValue1 = analogRead(A1); //Automatically sets pin to analog input
40-
Serial.print(" left val: ");
41+
Serial.print("A1: ");
4142
Serial.print(myValue1);
4243

43-
int myValue2 = analogRead(A3);
44-
Serial.print(" right val: ");
45-
Serial.print(myValue2);
46-
47-
int a5 = analogRead(A5);
48-
Serial.print(" A5: ");
49-
Serial.print(a5);
50-
5144
int internalTemp = analogRead(ADC_TEMP); //Read internal temp sensor. 3.8mV/C, +/-3C
52-
Serial.print(" internalTemp: ");
45+
Serial.print("\tinternalTemp: ");
5346
Serial.print(internalTemp);
5447

5548
int vss = analogRead(ADC_VSS); //Read internal VSS
56-
Serial.print(" vss: ");
49+
Serial.print("\tvss: ");
5750
Serial.print(vss);
5851

5952
//TODO enable battload
6053
int div3 = analogRead(ADC_DIV3); //Read VCC across a 1/3 resistor divider
61-
Serial.print(" VCC/3: ");
54+
Serial.print("\tVCC/3: ");
6255
Serial.print(div3);
6356

64-
// float vcc = (float)div3 * 6 / 1024.0; //Convert 1/3 VCC to VCC
65-
// Serial.print(" VCC: ");
66-
// Serial.print(vcc, 2);
67-
// Serial.print("V");
57+
float vcc = (float)div3 * 6 / 1024.0; //Convert 1/3 VCC to VCC
58+
Serial.print(" VCC: ");
59+
Serial.print(vcc, 2);
60+
Serial.print("V");
6861

6962
//pinMode(A4, OUTPUT); //Reset analog function to false.
7063

71-
//Todo: test overall read time
72-
/*long startTime = millis();
73-
uint32_t total = 0;
74-
for(int x = 0 ; x < 100 ; x++)
75-
{
76-
total += analogRead(16);
77-
}
78-
Serial.print(" total: ");
79-
Serial.print(total);
80-
Serial.print(" totalTime: ");
81-
Serial.print( (millis() - startTime) / 100);*/
82-
8364
Serial.println();
8465

8566
digitalWrite(LED, HIGH);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Auzhor: Owen Lyke
2+
/ Created: May 13 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates how to use millis() and micros()
6+
*/
7+
8+
void setup() {
9+
10+
Serial.begin(9600);
11+
12+
while(!Serial){}; //Wait for user to open terminal window
13+
14+
Serial.println("SparkFun Arduino Apollo3 STimer Example");
15+
Serial.printf("Compiled on %s, %s\n\n", __DATE__, __TIME__);
16+
}
17+
18+
void loop()
19+
{
20+
Serial.printf("Sec: %d, millis: %d, micros: %d, systicks: 0x%08X, sysoverflows: 0x%08X\n", seconds(), millis(), micros(), systicks(), sysoverflows());
21+
delay(1111); //Arbitrary delay
22+
}
Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,16 @@
1-
// Author: Owen Lyke
2-
// Created: April 2 2019
3-
// License: MIT. See SparkFun Arduino Apollo3 Project for more information
1+
/* Author: Owen Lyke
2+
Created: April 2 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
44
5-
// This example demonstrates that the IDE is able to compile the Ambiq Apollo3 HAL
6-
// Turn on verbose output and find the output path (i.e. ~/arduino_build_######/example0_compilation.ino.bin)
7-
// Use the Ambiq SDK + tools to upload the binary to your microcontroller
8-
9-
static int boardSetup(void);
5+
This example demonstrates that the IDE is able to compile the Ambiq Apollo3 HAL
6+
Turn on verbose output and find the output path (i.e. ~/arduino_build_######/example0_compilation.ino.bin)
7+
Use the Ambiq SDK + tools to upload the binary to your microcontroller
8+
*/
109

1110
void setup() {
1211
// put your setup code here, to run once:
13-
boardSetup();
14-
15-
am_util_stdio_terminal_clear();
16-
17-
am_util_stdio_printf("SparkFun Arduino Apollo3 Compilation Test\n");
18-
am_util_stdio_printf("Compiled on %s, %s\n\n", __DATE__, __TIME__);
19-
am_bsp_uart_string_print("Hello, World!\r\n"); // Sting_print has less overhead than printf (and less risky behavior since no varargs)
2012
}
2113

2214
void loop() {
2315
// put your main code here, to run repeatedly:
24-
25-
}
26-
27-
static int boardSetup(void)
28-
{
29-
// Set the clock frequency.
30-
am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_SYSCLK_MAX, 0);
31-
32-
// Set the default cache configuration
33-
am_hal_cachectrl_config(&am_hal_cachectrl_defaults);
34-
am_hal_cachectrl_enable();
35-
36-
// Configure the board for low power operation.
37-
am_bsp_low_power_init();
38-
39-
// Initialize the printf interface for ITM/SWO output.
40-
am_bsp_uart_printf_enable(); // Enable UART - will set debug output to UART
41-
//am_bsp_itm_printf_enable(); // Redirect debug output to SWO
42-
43-
// Setup LED's as outputs
44-
am_hal_gpio_pinconfig(AM_BSP_GPIO_LED_RED, g_AM_HAL_GPIO_OUTPUT_12);
45-
am_hal_gpio_pinconfig(AM_BSP_GPIO_LED_BLUE, g_AM_HAL_GPIO_OUTPUT_12);
46-
am_hal_gpio_pinconfig(AM_BSP_GPIO_LED_GREEN, g_AM_HAL_GPIO_OUTPUT_12);
47-
am_hal_gpio_pinconfig(AM_BSP_GPIO_LED_YELLOW, g_AM_HAL_GPIO_OUTPUT_12);
48-
49-
// Turn on the LEDs
50-
am_hal_gpio_output_set(AM_BSP_GPIO_LED_RED);
51-
am_hal_gpio_output_set(AM_BSP_GPIO_LED_BLUE);
52-
am_hal_gpio_output_set(AM_BSP_GPIO_LED_GREEN);
53-
am_hal_gpio_output_set(AM_BSP_GPIO_LED_YELLOW);
54-
55-
return 0;
5616
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
// Author: Owen Lyke
2-
// Created: April 9 2019
3-
// License: MIT. See SparkFun Arduino Apollo3 Project for more information
1+
/* Author: Owen Lyke
2+
Created: April 9 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
44
5-
// This example demonstrates usage of:
6-
// pinMode
7-
// delay
5+
This example demonstrates usage of:
6+
pinMode
7+
delay
8+
*/
89

9-
void setup() {
10-
// put your setup code here, to run once:
11-
am_util_stdio_terminal_clear();
10+
//Various boards have status LEDs on different pins
11+
//Most have LED_BUILTIN defined so just use that
12+
//But if you want, you can blink any pin
13+
14+
//#define blinkPin 37
15+
#define blinkPin LED_BUILTIN
1216

13-
am_util_stdio_printf("SparkFun Arduino Apollo3 Blink Example\n");
14-
am_util_stdio_printf("Compiled on %s, %s\n\n", __DATE__, __TIME__);
15-
am_bsp_uart_string_print("Hello, World!\r\n"); // Sting_print has less overhead than printf (and less risky behavior since no varargs)
16-
17-
pinMode(37, OUTPUT);
17+
void setup() {
18+
pinMode(blinkPin, OUTPUT);
1819
}
1920

2021
void loop() {
21-
// put your main code here, to run repeatedly:
22-
digitalWrite(37, LOW);
22+
digitalWrite(blinkPin, LOW);
2323
delay(1000);
24-
digitalWrite(37, HIGH);
24+
digitalWrite(blinkPin, HIGH);
2525
delay(1000);
2626
}

libraries/CoreTesting/examples/example1_gpio/example1_gpio.ino

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
1-
// Author: Owen Lyke
2-
// Created: May 2 2019
3-
// License: MIT. See SparkFun Arduino Apollo3 Project for more information
4-
5-
// This example demonstrates how to use Arduino HardwareSerial class functions
6-
// Uart objects inherit from HardwareSerial. Declare a Uart object with the following parameters:
7-
// Uart myUart(instance, rx, tx, rts, cts)
8-
// instance: either 0 or 1, corresponding to uart0 or uart1 in the Apollo3
9-
// rx pin: (opt.) the *pin* number to use for rx. must map to a valid rx pad on the apollo3 for the uart instance
10-
// tx pin: (opt.) the *pin* number to use for tx. must map to a valid tx pad on the apollo3 for the uart instance
11-
// rts pin: (opt.) the *pin* number to use for rts. must map to a valid rts pad on the apollo3 for the uart instance
12-
// cts pin: (opt.) the *pin* number to use for cts. must map to a valid cts pad on the apollo3 for the uart instance
13-
// *pin* means the variant's pin number, as opposed to the Apollo3 pad number. The provided number is mapped using the variant's pin map
14-
// Use AP3_UART_PIN_UNUSED if a particular function is unnecessary
15-
// Board-standard Uart objects can be declared in the variant configuration (variant.h and variant.cpp)
16-
17-
// For example, this is the definition of Serial found in the SparkFun Edge variant
18-
//Uart Serial(0, 49, 48);
19-
20-
#define SERIAL_PORT Serial
1+
/* Author: Nathan Seidle
2+
Created: June 12th, 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates usage of:
6+
Serial
7+
Serial1
8+
*/
219

2210
void setup() {
11+
Serial.begin(9600);
12+
Serial.println("Hello debug window!");
13+
14+
Serial1.begin(115200);
15+
Serial1.println("This prints on TX1/RX1 pins");
16+
}
2317

24-
SERIAL_PORT.begin(115200);
18+
void loop() {
19+
Serial.println("Time for a menu:");
20+
Serial.println("a) Activate the cheese");
21+
Serial.println("x) Exit");
22+
Serial.println();
2523

26-
while(!SERIAL_PORT){}; // todo: right now this falls straight through
24+
while (Serial.available() == true) Serial.read(); //Read any characters that may be sitting in the RX buffer before we wait for user input
2725

28-
SERIAL_PORT.println("SparkFun Arduino Apollo3 Serial Example");
29-
SERIAL_PORT.printf("Compiled on %s, %s\n\n", __DATE__, __TIME__); // Look! You can use printf, if you so choose
26+
while (Serial.available() == false) delay(1); //Wait for user input
3027

31-
SERIAL_PORT.print("Your Apollo3 variant has ");
32-
SERIAL_PORT.print(AP3_VARIANT_NUM_PINS);
33-
SERIAL_PORT.println(" pins.");
34-
SERIAL_PORT.println();
35-
}
28+
char incoming = Serial.read();
3629

37-
void loop() {
30+
if (incoming == 'a' || incoming == 'A')
31+
{
32+
Serial.println("How many cheeses to dispense?");
3833

39-
if(SERIAL_PORT.available()){
40-
while(SERIAL_PORT.available()){
41-
char c = SERIAL_PORT.read();
42-
SERIAL_PORT.write(c);
34+
while (Serial.available() == true) Serial.read(); //Read any characters that may be sitting in the RX buffer before we wait for user input
35+
36+
while (Serial.available() == false); //Wait for user to type a number
37+
unsigned int cheeseCount = Serial.parseInt(); //That's a lot of potential cheese
38+
39+
//Print to second serial port
40+
for (unsigned int x ; x < cheeseCount ; x++)
41+
{
42+
Serial1.println("Cheese!");
4343
}
44-
}
4544

45+
Serial.printf("Thank you. %d cheeses dispensed.\n\r", cheeseCount); //Did you see that?! We used printf!
46+
}
47+
else if (incoming == 'x' || incoming == 'X')
48+
{
49+
Serial.println("Exiting... Have a nice day.");
50+
while (1); //Freeze
51+
}
52+
else
53+
{
54+
Serial.print("Unknown choice: ");
55+
Serial.write(incoming);
56+
Serial.println();
57+
}
4658
}

0 commit comments

Comments
 (0)