Forum › Coding Corner › Coding Basics
- This topic has 13 replies, 4 voices, and was last updated 2 years, 7 months ago by
sakuyarules89.
-
AuthorPosts
-
-
December 6, 2021 at 10:18 pm #6622
Martyn
These sketches are referred to in the manuals. They help test functionality and teach concepts. Right-click and download the link to open it in the Arduino IDE. Alternatively, open a new sketch, then click on the link for the sketch. Copy the text into the new sketch and save it. Make sure you don’t miss the last } if copying and pasting.
MOTHERBOARD
The simple blink sketch: DOWNLOAD
Uses the RTC to show the date and time via the Serial Monitor: DOWNLOADCoding Basics – Blinks SOS: DOWNLOAD
Coding Basics – Blinks SOS using a for loop: DOWNLOADDIGITISER
Simple shiftOut sketch using a switch for mode select and the pot for dimming: DOWNLOAD
SENSOR ARRAY
Sensor Array Module Test Script: DOWNLOAD
Test Script for use with Serial Plotter: DOWNLOADCoding Basics: DHT11: DOWNLOAD
Coding Basics: LDR: DOWNLOAD
Coding Basics: Microphone: DOWNLOAD
Coding Basics: SD Card Write: DOWNLOADRGB MATRIX
RGB Matrix Test Sketch: DOWNLOAD
Coding Basics – Simple Animation: DOWNLOAD
-
This topic was modified 2 years, 9 months ago by
Martyn.
-
This topic was modified 2 years, 7 months ago by
Martyn.
-
This topic was modified 2 years, 9 months ago by
-
January 14, 2022 at 6:19 am #6741
cred718
RTC:99:5: error: expected ‘}’ at end of input
}
^
exit status 1
expected ‘}’ at end of inputIs what I am getting when I try to verify and compile. it is showing up for the very last } at line 99.
also when i try to use the RTC code it asks about the rtclib and that there is no directory.
-
January 18, 2022 at 6:39 pm #6749
vince
ran into that as well. All I did was add extra spaces on each of the comments on the code lines. Between the semi-colon and the //. fixed it for me.
-
January 19, 2022 at 12:08 pm #6750
Martyn
Hi Cred & Vince,
Throw another } at the end of the code when you get that error. You may have missed it when you copied the code. A straight copy-paste works fine for me.
For the RTClib to work you need to download the relevant library. Head to Tools, Manage Libraries… Type RTClib in the search box, then install the RTClib plugin, the one by Adafruit. I should have mentioned this, sorry.
Vince, that fix sounds strange… The compiler ignores extra spaces, so I’m not sure what is going on there.
Make sure all the { have matching }. Install the library and everything should work.
Cheers, M
-
-
February 1, 2022 at 5:33 pm #6788
sakuyarules89
I copied the digitizer code (only changed the pins), and have it running. The behavior is not what I expect though, “Mode 1” lights up all the colored LEDs, but none of the digits; “Mode 2” – 4 light all the segments in each digit for all the digits, but none of the LEDs. It looks like it doesn’t matter what I put in my bit, if I put B1xxxxxxx, it turns all the LEDs on, and B0xxxxxxx turns all the segments of all the digits on.
I realized initially I had one of the shift registers in backward (I thought both were supposed to be pointing to the center of the board), and the backward one got very hot. Do you think this burnt out, and that is why I’m seeing this behavior?
-
February 1, 2022 at 7:12 pm #6789
sakuyarules89
Sorry to double post, I don’t see an edit button. I found an extra shift register of the same type and tried putting it in, but I’m getting the same behavior.
-
February 2, 2022 at 8:10 pm #6790
Martyn
That is strange behaviour. Have you checked the underside of the board for any solder bridges? Some of the shift register’s pins might be bridged. Could you post a photo of the front and back of the board? Also, upload the exact sketch so I can have a look at that.
-
February 4, 2022 at 4:06 pm #6794
sakuyarules89
I’ve tried responding 3 or 4 times now, but it’s not showing up, is there maybe a character limit on the posts that I’m exceeding, or do they need to be approved if they have code? I can send you a direct e-mail if that would be easier.
-
February 7, 2022 at 2:19 pm #6799
Martyn
Hmm, Sorry about that, I have no idea what could be wrong… I’m new to hosting a forum, so I’ll have to do some digging. Email info@shortcircuits.cc in the meantime and I’ll take a look.
EDIT: I worked out the problem. I had to manually approve the post. Sorry about that.
-
-
-
-
February 7, 2022 at 2:42 pm #6793
sakuyarules89
I’ve tried to post this 3 or 4 times now, I’m not seeing it though, so I’ll try once or twice more:
I did a visual inspection, didn’t find any solder bridges. Then I tried with my multimeter, still didn’t find anything awry. Sorry if this double posts, after I hit submit the post just seemed to disappear, and isn’t showing up even after I refresh.
Info in pdf form
//Output Pin Variables const int OE = 2; // Shift Register Output Enable pin const int SER = 11; // Shift Register Serial Data pin const int CLK = 12; // Shift Register Clock pin const int LAT = 13; // Shift Register Latch pin //Input Pin Variables const int sw1 = A2; // Switch 1 pin const int Pot = A4; // Potentiometer pin (must be analog pin) const int sw2 = A5; // Switch 2 pin //Other Variables int mode = 1; // counter for Mode select int swState = 0; // Holds the current state of the switch int lastswState = 0; // Holds the previous state of the switch int potRead = 0; // Holds the current potentiometer value (0-1024) int potDimVal = 0; // Holds the converted dimming value for output to OE (0-255) //Void Setup - runs once at start void setup() { pinMode(OE, OUTPUT); pinMode(SER, OUTPUT); pinMode(CLK, OUTPUT); pinMode(LAT, OUTPUT); analogWrite(OE, 0); } //Void Loop - repeats forever void loop() { //DIM DISPLAY USING POTENTIOMETER potRead = analogRead(Pot); // Reads the pot and assigns potRead the same value potDimVal = map(potRead,0,1023,255,0); // maps potRead (0-1023) to potDimVal (255-0) analogWrite(OE,potDimVal); // Sets a PWM value (potDimVal) to the OE pin to set brightness //MODE SWITCHING swState = digitalRead(sw1); //read the pushbutton input pin if (swState != lastswState) // compare swState to its previous state, if it changed... { if (swState == HIGH) // ...and the current state is HIGH then the button was pressed { if (mode < 4) // if mode is less than the number of modes { mode++; // add 1 to mode, thus changing to the next mode } else // if mode is not less than the number of modes... { mode = 1; // ...set mode to 0 (the first mode) } } delay(5); // Delay a little bit to avoid bouncing } lastswState = swState; // save the current state as the last state //Shift Out Digits if (mode == 1) // if mode is equal to 1 then execute the following code { digitalWrite(LAT,LOW); // sets the latch low shiftOut(SER,CLK,LSBFIRST,B11101011); // shifts each bit in the given byte to the serial pin, sending the least significant (right most) bit first shiftOut(SER,CLK,LSBFIRST,B10001110); // shifts another byte which pushes the last through to the second register digitalWrite(LAT,HIGH); // sets the latch high } if (mode == 2) { digitalWrite(LAT,LOW); shiftOut(SER,CLK,LSBFIRST,B01001100); shiftOut(SER,CLK,LSBFIRST,B01001101); digitalWrite(LAT,HIGH); } if (mode == 3) { digitalWrite(LAT,LOW); shiftOut(SER,CLK,LSBFIRST,B01001001); shiftOut(SER,CLK,LSBFIRST,B00101011); digitalWrite(LAT,HIGH); } if (mode == 4) { digitalWrite(LAT,LOW); shiftOut(SER,CLK,LSBFIRST,B00101011); shiftOut(SER,CLK,LSBFIRST,B00010111); digitalWrite(LAT,HIGH); } }
-
February 7, 2022 at 3:41 pm #6806
Martyn
I tested your code and it works fine with my test boards. So it must be a fault with the hardware. The fault you described sounds like a problem with the left shift register (U5) as this shift register deals with the LEDs and the Digits. It sounds like one mode is turning on all the outputs and the other mode turns off all the outputs (LEDs turn on when outputs are on and digits turn on when outputs are off). We should test the shift register for faults. Take the chip out, then bend the output pins up (pins 15 & 1-7). Now reseat the chip in the holder and upload the following code:
const int OE = 2; const int SER = 11; const int CLK = 12; const int LAT = 13; void setup() { pinMode(OE, OUTPUT); pinMode(SER, OUTPUT); pinMode(CLK, OUTPUT); pinMode(LAT, OUTPUT); analogWrite(OE, 0); } void loop() { digitalWrite(LAT,LOW); shiftOut(SER,CLK,LSBFIRST,B10000000); digitalWrite(LAT,HIGH); }
Use your multimeter to check output 1 (pin 15) reads ~5V. Check the rest of the outputs read 0V. Now change the byte in the code to B0100000 and check the outputs. pin 15 should read 0V, pin 1 should read ~5V and the rest should read 0V. Keep changing the code and checking the readings. If anything looks wrong, try the other shift registers you have.
Other things to look at are the surface mount resistors and LEDs, which look a bit messy (well done for trying they are tricky). Also, try different ports for each connection, as all the connections to the Digitiser except the pot can be connected to any IO port (make sure you change the code to reflect changes).
Let me know what you find.
-
February 8, 2022 at 5:19 pm #6822
sakuyarules89
So I used your code, checked what you explained, everything looked fine; bent the pins back in, uploaded the old code, everything worked.
-_- Electronics, am I right? One question though: when I turn the potentiometer, the brightness of the LEDs/7-segment doesn’t change, but at a certain low point they turn off, is this right?
-
February 8, 2022 at 7:13 pm #6824
Martyn
Awesome! Glad it worked! Regarding the Pot, that sounds like you have it connected to a digital pin, not an analog pin. Or, you have OE connected to a non-PWM pin. Possibly… 🙂
-
February 10, 2022 at 4:08 pm #6827
sakuyarules89
It was the PWM one; works flawlessly now. Thank you again, kind sir!
-
-
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.