Jump to content

Hi everyone

 

Recently I recieved an assignment to write a little arduino program. But I cant figure it out with my little knowledge(in short:Arduino noob).

I know some sort of code would be useful but none of my codes worked, so I need to build this one from the ground.

So I need to program the arduino so it can do some things(duho.O)


But I have some condintions that I need to keep in mind.

So what is this assignment about.

I need to get a program which can perform the following things

 

-A preset function to switch between the following two functions. This switching happens via a button

-Demo mode, in this mode an RGB led slowly fades into another color. This continues untill u switch modes.

-Disco button. in this mode the RGB led needs to change colors when a button is pressed. 

 

Is there somebody out there who can help me and is willing to.

If there is need for any more information. please ask

 

Thanks in advance,

spijk860

 

 

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/
Share on other sites

Link to post
Share on other sites

I'm not versed with Arduinos, but I've mucked with a variety of microcontrollers to at least provide generic guidance. So to get a handle on this:

  • Know your IDE, which is the software you'll be using to develop the software. There should be plenty of tutorials online on how to set up a basic project and put in simple software for your kit.
  • Get familiar with how to debug the software. There should also be plenty of tutorials about this.
  • Figure out how to manipulate the inputs and outputs of your system. Learn how to manipulate your GPIO pins, how to set them up as inputs or outputs, how to capture inputs and triggers
  • Learn about the timers in the microcontroller, how to set them up, and how to get them to generate a periodic event.

But I feel this assignment has a lot of concepts that seems more like an intermediate level task than a beginner one, namely because you also should be using interrupts and PWMs (and I have a hard time generating a PWM signal without the use of an oscilloscope to verify it)

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10607607
Share on other sites

Link to post
Share on other sites

35 minutes ago, M.Yurizaki said:

I'm not versed with Arduinos, but I've mucked with a variety of microcontrollers to at least provide generic guidance. So to get a handle on this:

  • Know your IDE, which is the software you'll be using to develop the software. There should be plenty of tutorials online on how to set up a basic project and put in simple software for your kit.
  • Get familiar with how to debug the software. There should also be plenty of tutorials about this.
  • Figure out how to manipulate the inputs and outputs of your system. Learn how to manipulate your GPIO pins, how to set them up as inputs or outputs, how to capture inputs and triggers
  • Learn about the timers in the microcontroller, how to set them up, and how to get them to generate a periodic event.

But I feel this assignment has a lot of concepts that seems more like an intermediate level task than a beginner one, namely because you also should be using interrupts and PWMs (and I have a hard time generating a PWM signal without the use of an oscilloscope to verify it)

What u say its true. It is not a easy task. I already have some pieces of code right now. 

 

Using the internet I found some usefull things, bot none who would be really usefull in my case.

 

Thats why I ended up here with my question. There must be someone who can give me push in the right direction. 

 

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10607811
Share on other sites

Link to post
Share on other sites

Just now, spijk860 said:

What u say its true. It is not a easy task. I already have some pieces of code right now. 

 

Using the internet I found some usefull things, bot none who would be really usefull in my case.

 

Thats why I ended up here with my question. There must be someone who can give me push in the right direction.

Well, I can't really provide you with code since I don't have an Arduino (and it's a homework assignment, so that's even more of reason not to do it :P )

 

But when I used to do this sort of work, I'd do the following:

  • Get the I/O working.
  • Get interrupts working (most of the stuff I did was interrupt based so this was important)
  • Get timers going, verify this works by doing a simple overflow toggle on an output (e.g., LED)

I also would get the UART working ASAP, because having a communication line was valuable in what I did. But since you don't need a UART, I omitted it.

 

You don't need to build the entire thing at once. Build in pieces together and on top of each other.

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10607855
Share on other sites

Link to post
Share on other sites

31 minutes ago, M.Yurizaki said:

Well, I can't really provide you with code since I don't have an Arduino (and it's a homework assignment, so that's even more of reason not to do it :P )

 

But when I used to do this sort of work, I'd do the following:

  • Get the I/O working.
  • Get interrupts working (most of the stuff I did was interrupt based so this was important)
  • Get timers going, verify this works by doing a simple overflow toggle on an output (e.g., LED)

I also would get the UART working ASAP, because having a communication line was valuable in what I did. But since you don't need a UART, I omitted it.

 

You don't need to build the entire thing at once. Build in pieces together and on top of each other.

What level is this? interrupts etc don't get taught till 3year uni on the courses I am doing at the moment. Based off my knowledge of arduino and all its inbuilt libraries, this is a fairly simple project. I have got PWM outputs in a single line of code.

 

What I would do is:

Get the IO working, flashing led etc with delay command.

Then make it switch activated, hold the switch to enable the led.

Then make two modes, on and off.

Then add PWM to the modes.

Build up each mode till 

Progressively build each lighting mode till you are happy. 

 

There are some PWM inbuilt commands available which run at 500Hz. They should be fine for LED control but sucked for fans, and getting different frequencies gets somewhat hard, as then you have to delve into timer control etc.

 

 

Sync RGB fans with motherboard RGB header.

 

Main rig:

Ryzen 7 1700x (4.05GHz)

EVGA GTX 1070 FTW ACX 3.0

16GB G. Skill Flare X 3466MHz CL14

Crosshair VI Hero

EK Supremacy Evo

EVGA SuperNova 850 G2

Intel 540s 240GB, Intel 520 240GB + WD Black 500GB

Corsair Crystal Series 460x

Asus Strix Soar

 

Laptop:

Dell E6430s

i7-3520M + On board GPU

16GB 1600MHz DDR3.

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10608016
Share on other sites

Link to post
Share on other sites

10 minutes ago, unknownmiscreant said:

What level is this? interrupts etc don't get taught till 3year uni on the courses I am doing at the moment.

The concept of interrupts was taught in the first semester of the second year where I went. Actually implementing them though was in a third year course.

10 minutes ago, unknownmiscreant said:

Based off my knowledge of arduino and all its inbuilt libraries, this is a fairly simple project. I have got PWM outputs in a single line of code.

If that's the case then that makes things easier.

 

Still would rather do an interrupt based toggle switch though rather than a constant polling. :P

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10608072
Share on other sites

Link to post
Share on other sites

It can be done without interrupts , just by carefully writing instructions in an infinite loop and knowing how much time each instruction takes and at what frequency the arduino runs.

 

for example


 

// button reading, debouncing, we only want to react on a button press if user pressed button for let's say 5-10ms
// a button is considered pressed only when user lifts finger off the button so when you change from pressed to not pressed.

is button pressed ? (1 or 0 on a digital input)
  yes:  increment a variable by 1 (count how much button is pressed, when it's pressed for long enough then consider it a valid press)
  no :  is variable higher than some amount ? 
		yes : (means user lifted finger off the button after a few ms so it's a valid button press) 
			  change a variable that holds the "mode" of your program (if it's in disco mode or the other mode)
              reset the led to some default state (all colors off) for example
              set the variable below (which counts time between last action) to some high value to force a "refresh"
              OR maybe call a function which "initializes" the mode by setting the initial PWM mode for the three leds / random color
		no  : reset the variable to 0 (it's probably debouncing glitch, which happens right when you start pushing button down or lift finger off button)

// the actual meat of your program

increment another variable by 1 (count the time)
is variable big enough (did enough time passed that you want to perform next step in fade, or change the led color) ? 
	yes: is mode 1 ? call function which fades the led (changes pwm cycle of one of the rgb colors) 
		 is mode 2 ? call the function which changes the 3 colors at the same time 
		 reset the variable to 0 so that we count again the time. 
	no : carry on, loop to the beginning
    

// you can count how many cycles it takes to do the button pressing routing (you know it takes one cycle to add, 2 cycles for if then else etc
// you can estimate how many cycles the contents of the function will take 
// you know that arduino runs at 8 mhz , so you know it can do so many cycles can be done in 1ms ... 
// so it's just a matter of picking the right numbers for those variables 

// of course it wouldn't be super accurate since arduino adds a lot of junk when it converts what you type to actual microcontroller code, but nobody needs microsecond precision here and you can tweak those numbers until you like the smoothness of fades 

// later edit: of course if you want a good grade you'll want to make sure you don't cause overflow in variables.

For example let's say the code above will check if button is pressed every 1ms, and increments that variable by 1 and the variable is stored in memory in 2 bytes (up to 65536).

if a user presses button for more than around 65 seconds then you'd try to add 1 to 65536 and variable would overflow and maybe microcontroller would reset. So it would make sense to add an IF or something. .. is variable higher than (some unrealistic value, like 20000 for 20s)? , if yes then reset it to equivalent of 5s..

 

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10608111
Share on other sites

Link to post
Share on other sites

19 minutes ago, M.Yurizaki said:

The concept of interrupts was taught in the first semester of the second year where I went. Actually implementing them though was in a third year course.

If that's the case then that makes things easier.

 

Still would rather do an interrupt based toggle switch though rather than a constant polling. :P

I'm in 1st year, doing 2nd year electronics and software courses, and they specifically state interrupts don't get taught till 3rd year. I have written code that uses IOC and timer interrupts to count pulses on an input pin and output sub-millisecond accurate radio pulses on a average current draw of a 70 uA including radio. But I suspect thats really beyond the scope of this assignment.

 

If I was doing this project, I would constantly poll the button, and update the led in a while loop or similar, with a delay function at the bottom to pace it. I know full well its a pretty terrible way of doing it, but there is no power draw cap, and its easy to write, understand and maintain. Its what I did for my custom case lighting controller, and the code for that is in no way elegant. Its quick and dirty, with no optimization, but very easy to modify and add to. My loop is actually paced by the time taken to output everything to the individually addressable LED strip via UART.

Sync RGB fans with motherboard RGB header.

 

Main rig:

Ryzen 7 1700x (4.05GHz)

EVGA GTX 1070 FTW ACX 3.0

16GB G. Skill Flare X 3466MHz CL14

Crosshair VI Hero

EK Supremacy Evo

EVGA SuperNova 850 G2

Intel 540s 240GB, Intel 520 240GB + WD Black 500GB

Corsair Crystal Series 460x

Asus Strix Soar

 

Laptop:

Dell E6430s

i7-3520M + On board GPU

16GB 1600MHz DDR3.

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10608122
Share on other sites

Link to post
Share on other sites

Having a look around for how Arduinos handle interrupts (and it appears to be dependent on the board you have), I found an example and it doesn't appear to be all that difficult to implement either: https://www.allaboutcircuits.com/technical-articles/using-interrupts-on-arduino/

 

To steal their code, which all it's doing is using a button as an LED switch:

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
volatile int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, CHANGE);
}

void loop() {
  // Nothing here!
}

void pin_ISR() {
  buttonState = digitalRead(buttonPin);
  digitalWrite(ledPin, buttonState);
}

OP can decide how they want to do it though. I'm just providing a tool to help with the task.

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10608178
Share on other sites

Link to post
Share on other sites

1 hour ago, spijk860 said:

Thanks for the replies, U all gave me something to start of with. 

 

Edit: So I searched for a few code examples around the internet, with a few of them I could comlpete one mode of the assignment. But now I need some help with the butted rgb mode. I have the following code but I cant make the led change to another color. it keeps being blue. 

things like Rood,Groen and Blauw are the following colors: red,green,blue

 


int Rood = 6;
int Groen = 5;
int Blauw = 7;

int IN = 3;

int current = 0;

int rgb[] = { Rood, Groen, Blauw };

void setup() {
  pinMode(IN, INPUT);
  pinMode(Rood, OUTPUT);
  pinMode(Groen, OUTPUT);  
  pinMode(Blauw, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if(digitalRead(IN) == HIGH) {
    current++;
    current = current == 3 ? 0 : current;
    delay(500);
  }
  digitalWrite(Rood, LOW);  
  digitalWrite(Groen, LOW);
  digitalWrite(Blauw, LOW);  
  digitalWrite(rgb[current], HIGH);
  delay(100);
}

 

 

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10609476
Share on other sites

Link to post
Share on other sites

On 26-10-2017 at 10:05 AM, spijk860 said:

 

Leds zijn leds. Volgens mij kun je die niet veranderen. Kan ik tenminste niet met mijn kit.

 

PS welk jaar doe je? Ik zit jaar 1 en hoef alleen maar een dom stoplicht te maken xD

 

Leds are leds. I don't think you can change Them. I can't whith my adruino kit. 

 

PS which year are you following? I am in year 1 and all i have to do is make a dumb traffic light xD

Main PC:

CPU: AMD Ryzen 7 5700X3D | RAM:Corsair LPX 3200 mhz (32GB) 

Mobo:ASUS Strix B550-F Wifi | GPU: Gigabyte 9070

Case: Sharkoon Nightshark RGB| Storage: 500 GB 970 EVO Plus 1 TB WD blue 500 GB Samsung HDD

Monitor: iiyama G-Master G2470HSU-B1 165Hz

Powersupply: Cooler Master GX III Gold 750

 

 

Main Laptop

CPU: AMD Ryzen 7 4800H | RAM: Team group 16 GB 2666 mhz

GPU: RTX 2060 (MXM swappable)

Monitor: 1080p 120Hz

Storage: 2x 1 TB Samsung 970 EVO NVMe (no raid)

 

 

Second Laptop

CPU: Intel Core I5 1235u,  RAM: Crucial 16 GB 3200 mhz

GPU: IrisXe 80 eu

Storage: 512 GB WD Digital SN530 NVMe

 

Phone:

Xiaomi MI 11

 

Work Phone:

Samsung Xcover 6pro

 

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10619713
Share on other sites

Link to post
Share on other sites

On 10/26/2017 at 4:05 AM, spijk860 said:

 

Are you sure the led you're using is RGB? there is a difference it will have 4 leads coming from it

My daily driver: The Wrath of Red: OS Windows 10 home edition / CPU Ryzen TR4 1950x 3.85GHz / Cooler Master MasterAir MA621P Twin-Tower RGB CPU Air Cooler / PSU Thermaltake Toughpower 750watt / ASRock x399 Taichi / Gskill Flare X 32GB DDR4 3200Mhz / HP 10GB Single Port Mellanox Connectx-2 PCI-E 10GBe NIC / Samsung 512GB 970 pro M.2 / ASUS GeForce GTX 1080 STRIX 8GB / Acer - H236HLbid 23.0" 1920x1080 60Hz Monitor x3

 

My technology Rig: The wizard: OS Windows 10 home edition / CPU Ryzen R7 1800x 3.95MHz / Corsair H110i / PSU Thermaltake Toughpower 750watt / ASUS CH 6 / Gskill Flare X 32GB DDR4 3200Mhz / HP 10GB Single Port Mellanox Connectx-2 PCI-E 10GBe NIC / 512GB 960 pro M.2 / ASUS GeForce GTX 1080 STRIX 8GB / Acer - H236HLbid 23.0" 1920x1080 60Hz Monitor HP Monitor

 

My I don't use RigOS Windows 10 home edition / CPU Ryzen 1600x 3.85GHz / Cooler Master MasterAir MA620P Twin-Tower RGB CPU Air Cooler / PSU Thermaltake Toughpower 750watt / MSI x370 Gaming Pro Carbon / Gskill Flare X 32GB DDR4 3200Mhz / Samsung PM961 256GB M.2 PCIe Internal SSDEVGA GeForce GTX 1050 Ti SSC GAMING / Acer - H236HLbid 23.0" 1920x1080 60Hz Monitor

 

My NAS: The storage miser: OS unRAID v. 6.9.0-beta25 / CPU Intel i7 6700 / Cooler Master MasterWatt Lite 500 Watt 80 Plus / ASUS Maximus viii Hero / 32GB Gskill RipJaw DDR4 3200Mhz / HP Mellanox ConnectX-2 10 GbE PCI-e G2 Dual SFP+ Ported Ethernet HCA NIC / 9 Drives total 29TB - 1 4TB seagate parity - 7 4TB WD Red data - 1 1TB laptop drive data - and 2 240GB Sandisk SSD's cache / Headless

 

Why did I buy this server: OS unRAID v. 6.9.0-beta25 / Dell R710 enterprise server with dual xeon E5530 / 48GB ecc ddr3 / Dell H310 6Gbps SAS HBA w/ LSI 9211-8i P20 IT / 4 450GB sas drives / headless

 

Just another server: OS Proxmox VE / Dell poweredge R410

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10619838
Share on other sites

Link to post
Share on other sites

On 28-10-2017 at 11:43 PM, Arjan W said:

Leds zijn leds. Volgens mij kun je die niet veranderen. Kan ik tenminste niet met mijn kit.

 

PS welk jaar doe je? Ik zit jaar 1 en hoef alleen maar een dom stoplicht te maken xD

 

Leds are leds. I don't think you can change Them. I can't whith my adruino kit. 

 

PS which year are you following? I am in year 1 and all i have to do is make a dumb traffic light xD

1e jaar HBO, stoplichtje lukt mij ook nog wel. de rest niet

First year, A traffic light isnt that difficult, I can program that, the rest is gibberish to me.

 

On 29-10-2017 at 12:29 AM, mrbilky said:

Are you sure the led you're using is RGB? there is a difference it will have 4 leads coming from it

100% sure, I have 4 leads from the LED

Link to comment
https://linustechtips.com/topic/851123-arduino-assignment/#findComment-10625785
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×