can somebody help me write arduinoprogram

i am new to any sort of programming.i am not going to lie but i have a project too do at university.where the teacher has not taught us anything at all.everyone in the class is in the same boat, that is or already has sunk. we have sent hundreds of complaints to the dean but nothing has been done.

basically he has given us a link to his website (which is http://www.cse.dmu.ac.uk/~sexton/ENGD2003/433page.html )and we have to produce the same. that is all we have been told by him.no help what so ever.
the task is two write an arduino programm in pairs where one arduino is transmitting and the other is recieving.what we have to recieve is shown in the table in the link above.the reciever code is given, but it must be edited to show what the table looks like.if anyone can make sense of it or if anyone is a "G" and would kindly write a tranmitter code i would be great full.

apart from the arduino he has also given us some"433MHz simplex radio frequency link" where one is attached to the transmitter and other to the reciever. if soomeone is willing to help but cant make sense of it please message me, maybe we could figure it out together.

this is what the steps are for writing transmitter code.
step1)include narcoleptic delay library(the program is suppose to send date for 1 second and sleep for 60 seconds), eeprom library store system id and node id in the eeprom), and virtual wire library to transmit data.

system id=0 and node id =2.
step 2)display number zero on 7seg 0 using potentiometer, press button1 to store number in eeprom.display num 2 on 7seg display using potentiometer,press button 2 to store number in eeprom.(note that both numbers should be stored in the same location on the eeprom therfore system id and node id must be 4bits each as one location of eeprom is8bit long.

step3)i dont know, and the teacher woont help us.the only help is the link above.

thanks

Is your shift key broken?

step1)include narcoleptic delay library(the program is suppose to send date for 1 second and sleep for 60 seconds), eeprom library store system id and node id in the eeprom), and virtual wire library to transmit data

English, please.

I can't say I'm surprised that you aren't getting much sympathy.

You're at university. You should be learning to solve problems. At school, you might have expected to be shown examples of similar problems and walked through the techniques to solve them. By the time you reach university you should be learning how to find solutions for yourself.

Break the problem down into small parts that you can solve independently. There are several obvious parts to your problem which can be tackled separately, and individually none of them are hard.

If you have two Arduinos and a radio transmitter/receiver pair, you should be able to establish one way comms. The 433MHz units shown in the picture are not unusual and anyone familiar with Google should be able to find some example code showing how to drive them.

Reading an analog value from a potentiometer and converting that value into a digit is easy enough. You could simply print that over the serial port to confirm that the result is right.

Displaying a digit on a 7-seg display is also easy. Google will show you a million examples of code displaying a digit on a 7-seg display.

Savings values in EEPROM is straight forward and you should have no trouble finding examples of it.

Putting the board to sleep for a few seconds is also a well-known problem which has been covered by many tutorials.

Putting that together with some control logic to keep track of what the device is supposed to be doing, inputting and saving the configuration and then applying it is the only part of this which seems novel, and it's hardly rocket science.

If you get stuck with any of these easy problems then you could always ask for help, and if there are problems you simply can't get past then you can still have a working solution which shows that you're got the other features working. Can't get the analog input to work? Just type the number into the serial port. Can't get the configuration to save and reload? Make it volatile. Can't get the display to work? Back to the serial port again. Can't get comms to work? Print out what you were trying to send and prove that everything else does what it's supposed to. Can't get the sleep to work? So what, it's not as if you're going to run out of power during a demo.

But don't throw your hands up and say you're being asked to do something unreasonable or you can't do it without somebody leading you by the nose. It's a completely reasonable project, and you should IMO just get on with it and demonstrate that you're capable of using your initiative to solve problems.

Remember: your lecturer doesn't want the solution; he wants you to demonstrate that you're capable of tackling the problem effectively.

Lovely stuff.
This should be in a sticky.

Who did Edison, Diesel or Whittle turn to for advice?

...R

PeterH:
I can't say I'm surprised that you aren't getting much sympathy.

You're at university. You should be learning to solve problems.

...snip....

can anybody tell me the correctness of this following code according to the task i have been asked to perform:
#include <Narcoleptic.h>
#include <EEPROM.h>
#include <VirtualWire.h>

#define POT1 0
#define POT2 1
#define POT3 2
#define LATCH 7
#define CLOCK 8
#define DATA 4
#define BUTTON1 10
#define BUTTON2 11
#define RX_PIN 4

const byte seven_segment[16]={B11000000,B11111001,B10100100,B10110000,B10011001,B10010010,B10000010,B11111000,B10000000,B10011000,B10001000,B10000011,B11000110,B10100001,B10000110,B10001110};
int x;
int addr = 0;
int buttonState = 0;
int buttonState2 = 0;
char b1;
char b2;

const int led = 5;
const int transmit_pin = 12;
const int receive_pin = 2;
const int vcc = 13;

void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(BUTTON1, 1);
pinMode(BUTTON2, 1);
pinMode(POT1, INPUT);
pinMode(LATCH, OUTPUT);
pinMode(CLOCK, OUTPUT);
pinMode(DATA, OUTPUT);
digitalWrite(vcc, HIGH);

vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
//vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}

byte count = 1;

void loop(){
{
x=analogRead(POT1)>>6;
digitalWrite(LATCH,LOW);
shiftOut(DATA,CLOCK,MSBFIRST,seven_segment[x]);
digitalWrite(LATCH,HIGH);
}

b1=bitWrite(buttonState, 0,digitalRead(BUTTON2)); //for the bottom bit
b2=bitWrite(buttonState, 1,digitalRead(BUTTON1)); //for the other bit
Serial.println(buttonState);
delay(100);

buttonState=digitalRead(BUTTON1);
if (buttonState == LOW){
EEPROM.write(addr, x);
}

char msg[5] = {analogRead(POT1)>>6,analogRead(POT2)>>2,analogRead(POT3)>>2,b1,b2};

digitalWrite(led, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, 5);
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led, LOW);
Narcoleptic.delay(4000);
}

And showing that you have not bothered to read the sticky at the top of this forum exmplaining how to use code tags, really shows your actual unwillingness to learn.

I'm sorry, Santz, but I seriously doubt that you are going to get any help here with your approach to this. Though I do respect your honesty in telling us it is a university project. That alone would not have precluded my help. But as far as I can tell, the real problem here is that you are too impatient to do the 'work' involved in learning something and want others to solve your problems. Perhaps you should consider management as your career choice, instead?

this is the code that i have written:

#include <Narcoleptic.h>
#include <EEPROM.h>
#include <VirtualWire.h> 

#define POT1 0
#define POT2 1
#define POT3 2
#define LATCH 7
#define CLOCK 8
#define DATA 4
#define BUTTON1 10
#define BUTTON2 11
#define RX_PIN 4 

const byte seven_segment[16]={B11000000,B11111001,B10100100,B10110000,B10011001,B10010010,B10000010,B11111000,B10000000,B10011000,B10001000,B10000011,B11000110,B10100001,B10000110,B10001110};
int x;
int addr  = 0; 
int buttonState = 0; 
int buttonState2 = 0; 
char b1; 
char b2;

const int led = 5;
const int transmit_pin = 12;
const int receive_pin = 2;
const int vcc = 13;

void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT); 
pinMode(BUTTON1, 1);
pinMode(BUTTON2, 1);
pinMode(POT1, INPUT);
pinMode(LATCH, OUTPUT);
pinMode(CLOCK, OUTPUT);
pinMode(DATA, OUTPUT); 
digitalWrite(vcc, HIGH);

vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
//vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000);	 // Bits per sec
}

byte count = 1;

void loop(){
{
x=analogRead(POT1)>>6;
  digitalWrite(LATCH,LOW);
  shiftOut(DATA,CLOCK,MSBFIRST,seven_segment[x]);
  digitalWrite(LATCH,HIGH);
}

b1=bitWrite(buttonState, 0,digitalRead(BUTTON2));    //for the bottom bit
b2=bitWrite(buttonState, 1,digitalRead(BUTTON1));    //for the other bit
Serial.println(buttonState);
delay(100);

buttonState=digitalRead(BUTTON1);
if (buttonState == LOW){
EEPROM.write(addr, x);
}

char msg[5] = {analogRead(POT1)>>6,analogRead(POT2)>>2,analogRead(POT3)>>2,b1,b2};

digitalWrite(led, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, 5);
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led, LOW);
Narcoleptic.delay(4000);
}

can you please help me geet rid of these errors:

Transmitter.cpp: In function 'void setup()':
Transmitter:41: error: 'vw_set_tx_pin' was not declared in this scope
Transmitter:42: error: 'vw_set_rx_pin' was not declared in this scope
Transmitter:44: error: 'vw_set_ptt_inverted' was not declared in this scope
Transmitter:45: error: 'vw_setup' was not declared in this scope
Transmitter.cpp: In function 'void loop()':
Transmitter:71: error: 'vw_send' was not declared in this scope
Transmitter:72: error: 'vw_wait_tx' was not declared in this scope
Transmitter:74: error: 'Narcoleptic' was not declared in this scope

santz:
can anybody tell me the correctness of this following code according to the task i have been asked to perform:

I haven't bothered looking at the code because there's quite a lot of it, it isn't in code tags (so I can't be sure it displayed correctly in the forum) and you haven't given any indication that there's any reason to expect a problem in it or what sort of problem we'd be looking for.

If it's intended to be the whole solution, I suggest that breaking the problem down into small pieces and solving them individually would be a better approach. Having written the code and (presumably) knowing what it's supposed to do, the logical next step would be to compile it, run it and see whether it works correctly. Does it compile? Does it run? Does it do what you intend?

at the moment i am getting the following errors.

Transmitter.cpp: In function 'void setup()':
Transmitter:41: error: 'vw_set_tx_pin' was not declared in this scope
Transmitter:42: error: 'vw_set_rx_pin' was not declared in this scope
Transmitter:44: error: 'vw_set_ptt_inverted' was not declared in this scope
Transmitter:45: error: 'vw_setup' was not declared in this scope
Transmitter.cpp: In function 'void loop()':
Transmitter:71: error: 'vw_send' was not declared in this scope
Transmitter:72: error: 'vw_wait_tx' was not declared in this scope
Transmitter:74: error: 'Narcoleptic' was not declared in this scope

i kind of figured out all these errors are due to the narcoleptic library

vw_set_tx_pin' was not declared in this scope

I kind of figured these errors are due to the Virtual Wire library, or more likely, the lack of a Virtual Wire library. ("vw" is the clue)

It isn't a core library - have you downloaded it?
Where did you put it?

Actually, most of them are problems with the way you are using the virtualwire library. And the one error regarding narcolpetic is because you are trying to use it as an object, but never declared it.

Honestly, your lack of understanding about how your own code is suppose to work tells me that you didn't actually write this.

is written in pairs but my partner is not coming to uni atm as he has personal problems. so fully not mine.please dont doubt me.i agree i have not much understaanding of arduino programming. yes narcolpetic.h library is placed in the correct directory.i have placed in a folder called libraries.where my arduiino code is placed.

But have you created an instance of it (via the constructor) in your code (no, you haven't)? You must do that before you can try to use it as an object (the narcoleptic.delay part.) Open the narcoleptic code and look at the function called narcoleptic::narcoleptic. That will tell you how to create an instance of that object in your code. That is called a constructor.

And you need to answer AWOLs question about the virtualwire library. That is the majority of your problem.

yes i have downloaded narcolpeptic library and put in in the correct directory, where all the other libraries are.

ok i have managed to get rid off all the problems.but when i open the serial port the only thing that it is being transmitted is the number "2" regardless of changing the potentiometer.here is the final code.please help me on figuring out why it is only transmitting "2".

#include <Narcoleptic.h>
#include <EEPROM.h>
#include <VirtualWire.h> 

#define POT1 0
#define POT2 1
#define POT3 2
#define LATCH 7
#define CLOCK 8
#define DATA 4
#define BUTTON1 10
#define BUTTON2 11
#define RX_PIN 4 

const byte seven_segment[16]={B11000000,B11111001,B10100100,B10110000,B10011001,B10010010,B10000010,B11111000,B10000000,B10011000,B10001000,B10000011,B11000110,B10100001,B10000110,B10001110};
int x;
int addr  = 0; 
int buttonState = 0; 
int buttonState2 = 0; 
char b1; 
char b2;

const int led = 5;
const int transmit_pin = 12;
const int receive_pin = 2;
const int vcc = 13;

void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT); 
pinMode(BUTTON1, 1);
pinMode(BUTTON2, 1);
pinMode(POT1, INPUT);
pinMode(LATCH, OUTPUT);
pinMode(CLOCK, OUTPUT);
pinMode(DATA, OUTPUT); 
digitalWrite(vcc, HIGH);

vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
//vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000);	 // Bits per sec
}

byte count = 1;

void loop(){
{
x=analogRead(POT1)>>6;
  digitalWrite(LATCH,LOW);
  shiftOut(DATA,CLOCK,MSBFIRST,seven_segment[x]);
  digitalWrite(LATCH,HIGH);
}

b1=bitWrite(buttonState, 0,digitalRead(BUTTON2));    //for the bottom bit
b2=bitWrite(buttonState, 1,digitalRead(BUTTON1));    //for the other bit
Serial.println(buttonState);
delay(100);

buttonState=digitalRead(BUTTON1);
if (buttonState == LOW){
EEPROM.write(addr, x);
}

char msg[5] = {analogRead(POT1)>>6,analogRead(POT2)>>2,analogRead(POT3)>>2,b1,b2};

digitalWrite(led, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, 5);
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led, LOW);
Narcoleptic.delay(4000);
}

Your code is riddled with all kinds of logical errors, and not even close to functioning code. But the reason that you are only getting "2" is because this:

Serial.println(buttonState);

The only thing you are sending over the serial port is the value of buttonstate. And that isn't including the pot values at all.

This is what you probably should be sending:

char msg[5] = {analogRead(POT1)>>6,analogRead(POT2)>>2,analogRead(POT3)>>2,b1,b2};

But, you are also using the buttonstate variable inconsistently. First you are packing the bits with two different button statuses, but then you are changing it with only button1.

I'm sure this is a silly question ... but what is the code supposed to do? How about helping us by including extensive comments in it? Put in twice as many comments as you think necessary because when you come back to this program after 6-months absence you won't remember any of it.

I don't get the impression that you know how to debug programs - something that has to be done with EVERY program because it's very difficult to get everything right first time. Put in extra Serial.print statements to show the values of variables as the program runs. Think about what outputs would show clearly where a problem is and what it is. If something isn't behaving as you expect put in some extra code - for example setting values that would normally come from a button or another device so that they are predictable.

Program code can be hard to follow, and C++ doesn't help with its squiggly brackets etc. Get into the habit of indenting code so that the bits that belong together are obvious without having to count brackets.

Have you any books about programming?

Have you the Atmega datasheet with all the technical details about the microprocessor?

...R

Just out of curiosity I decided to look at the instructions you were given. It all seems pretty straightforward to me, and I'm just a self-taught programmer.

Perhaps the problem is that you are trying to eat your elephant in one mouthful.

  1. I don't know what narco-whatever does.
  2. I don't know what virtualwire does.
  3. I have a vague idea what eeprom.h does but I've never used it.
  4. I haven't used any wireless devices, never mind the ones that are specified.
  5. I have used a temperature sensor (but not with my Arduino) but I haven't come across the ones that are mentioned.

So there are 5 small learning tasks, all of which are achievable, one by one. Write a little Arduino program to try out each piece and satisfy yourself that you know how to make it work. At the end writing the program that brings it all together will be easy and obvious.

And for virtually every commercial electronic device on the planet it's possible to download the datasheet.

Have fun

...R

Why not consider another career path? Since you waited until you couldn't put it off any more to try and learn embedded electrical engineering concepts, why bother sweating it now? You couldn't even be slightly interested in the field, or it would be a personal hobby and you wouldn't be this lost. If you do not personally enjoy engineering and harbor an obsession to solve challenging problems, then you will never be any good at it. Why be miserable for the rest of your life, change careers to something that interests you. I'm not trying to be mean, just asking you to take another look and decide if you really want to keep at this. Peace. :slight_smile:

to afremont and others instead of discouraging it is better if you don't reply at all.why waste your time clicking on the reply button and typing stuff that is not relevant to the question asked in this thread???better not reply at all.
i have almost managed to solve the problem (by myself) and i think i have done good job of it keeping in mind that i had no programming knowledge two days ago and now write basic codes.

and the fact that your telling me to choose a different career path!!why should I? are you career consultant?(or whatever you call that occupation).for your not so kind information i am studying electronic engineering and achieved 1st class Hon so for all my modules so far, except this module. and i think i will succeed in this as well.