Devices & Components
Arduino Nano 33 IoT
Segger J-Link Probe
Female/Female Jumper Wires
Hardware & Tools
Solder Flux, Soldering
Solder Wire, Lead Free
Soldering iron (generic)
Software & Tools
Visual Studio 2017
Arduino IDE
Visual Micro
Project description
Code
Nano33IoTProject.ino
arduino
Main Sketch file used in video
1const int motor = 12; 2int currentMotorPWM = 0; 3unsigned long currentPeriodStartTime = 0; 4unsigned int currentPeriod_MS = 1000; 5unsigned int currentResolution = 254; 6unsigned int maxResolution = 254; 7int currentPWMVal = 0; 8unsigned long loopCounter = 0; 9 10void setup() { 11 pinMode(motor, OUTPUT); 12 analogWrite(motor, currentPWMVal); 13} 14 15void loop() { 16 currentPWMVal = calculateCurrentPWM_sine((millis() - currentPeriodStartTime) % currentPeriod_MS); 17 pwmWrite(currentPWMVal); 18 loopCounter++; 19} 20
Nano33IoTProject.ino
arduino
Main Sketch file used in video
1const int motor = 12; 2int currentMotorPWM = 0; 3unsigned long currentPeriodStartTime = 0; 4unsigned int currentPeriod_MS = 1000; 5unsigned int currentResolution = 254; 6unsigned int maxResolution = 254; 7int currentPWMVal = 0; 8unsigned long loopCounter = 0; 9 10void setup() { 11 pinMode(motor, OUTPUT); 12 analogWrite(motor, currentPWMVal); 13} 14 15void loop() { 16 currentPWMVal = calculateCurrentPWM_sine((millis() - currentPeriodStartTime) % currentPeriod_MS); 17 pwmWrite(currentPWMVal); 18 loopCounter++; 19} 20
Calcs.ino
arduino
Secondary INO sketch used in Debugger video
1// Encapsualtion 2int calculateCurrentPWM_spiky(unsigned long periodTime) { 3 return calculateCurrentPWMMultiplier(periodTime) * currentResolution; 4} 5 6int calculateCurrentPWM_sine(unsigned long periodTime) { 7 return 8 round( 9 abs(int( 10 ( 11 sin( 12 ( 13 double(calculateCurrentPWM_spiky(periodTime)) 14 / 165.00 15 ) 16 ) 17 ) 18 * double(currentResolution) 19 ) 20 ) 21 ); 22} 23 24 25int oldValue = -1; 26void pwmWrite(int value) { 27 if (oldValue != value) { 28 analogWrite(motor, value); 29 oldValue = value; 30 Serial.print(","); 31 Serial.print(value); 32 } 33} 34 35double calculateCurrentPWMMultiplier(unsigned long periodTime) { 36 if ((double(periodTime % currentPeriod_MS) / double((currentPeriod_MS / 2.00))) <= 1.00) { 37 return (double(periodTime % currentPeriod_MS) / double((currentPeriod_MS / 2.00))); 38 } 39 else { 40 return (1.00 - ((double(periodTime % currentPeriod_MS) - double((currentPeriod_MS / 2.00))) / double((currentPeriod_MS / 2.00)))); 41 } 42} 43
Downloadable files
Arduino Nano 33 IoT to Debugger Wiring
Example of how to wire the Arduino Nano 33 IoT to an external debugger. The header shown is from the Segger JLINK and we are using it in SWD mode here.
Arduino Nano 33 IoT to Debugger Wiring

Arduino Nano 33 IoT to Debugger Wiring
Example of how to wire the Arduino Nano 33 IoT to an external debugger. The header shown is from the Segger JLINK and we are using it in SWD mode here.
Arduino Nano 33 IoT to Debugger Wiring

Comments
Only logged in users can leave comments