Looking for appropriate sensors for medium diploma graduation projects

Go To Last Post
89 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolfrose wrote:
I tried to write what pops into my head but I did a quick search and it turns out the this strategy belongs to C++, and I have to be familiar with classes properties and features to know about this method. But in its simplest form I think it's the getter function in C++.    

 

Why would I suggest it as an option if it was C++ only? Why did you need to search - I basically gave you the answer - all you had to do was fill in the function. Again, you've chosen to overlook a learning opportunity. Somehow I think we've been through the same process before....

 

Kartman wrote:
You'd normally do digit multiplexing in a timer interrupt. Using soft timers will lead to brightness modulation.

You've still not done this, but then again, you're using an i2c expander. Considering you can get i2c devices that do the display multiplexing for you or even non i2c devices. These can be got for little money off ebay. Doing it via an i2c expander is making a rod for your own back. If you make poor choices you spend inordinate amounts of time trying to fix the issues you've created rather than going for a sensible solution that just works.

 

 You've also not looked at how you can simplify your code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

2. write an accessor function. Something like setTaskTimer(uint8_t task, uint32_t time); Make that function visible to all your files

 

#2 is the technically more correct solution. Can you suggest why?

 

OK, so I think this could be done this way:

 

1. By developing this function in the multitasking library as an "extern".

2. Then any function in the other libraries should have an extra parameter with the time amount.

3. Register the functions address and store it in an enum.

 

How about that?

 

 

 

 

Kartman wrote:

Why would I suggest it as an option if it was C++ only? Why did you need to search - I basically gave you the answer - all you had to do was fill in the function. Again, you've chosen to overlook a learning opportunity. Somehow I think we've been through the same process before....

 

OK, if so then I think what you meant is to develop a function that is visible to all the libraries by defining it as "extern", I just pass the task number, and I think at this point I have to use function pointers. I tried to think of a way to register the function address in any library and store them in an array or enum.

 

 

Kartman wrote:
You've still not done this, but then again, you're using an i2c expander. Considering you can get i2c devices that do the display multiplexing for you or even non i2c devices. These can be got for little money off ebay. Doing it via an i2c expander is making a rod for your own back. If you make poor choices you spend inordinate amounts of time trying to fix the issues you've created rather than going for a sensible solution that just works.

Well, anyway we must use this board now, because there's no time to order any good breakout boards from eBay or Aliexpress. I know about these things and I absolutely love them, I normally don't do things in my own soldering but this was because I was thinking to do counters using 74LS47, 2 PNP transistors, 8 resistors and 2 common anode 7-segment displays.

 

But you absolutely right that was a come back to me because the trainees didn't know how to fix them as I was hoping to, so the fixing was my job and it took quite amount of time fixing soldering issues, absolutely my mistake. All my personal stuff are breakout boards from Aliexpress. But anyway I should learn from this mistake and try to prepare things to be easy for me and not expecting a lot from the trainees.

 

 You've also not looked at how you can simplify your code.

Hmmmm this is the best thing I could do about the code, what you suggest? Run all the displays with one timer interrupt?

 

 

===========================================================================================================

 

These are the boards, upto this level I think it's acceptable, but of course looking to improve it.

 

 

Last Edited: Sun. Dec 2, 2018 - 12:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I think you’re guessing - how do you store something in an enum? If the task is to store a value into an array, then you’re way off track. Think simple.

Did you really use 74ls47’s? I was ten years old when I last used them. Then you’ve used an i2c expander. You like doing things the hard way.

As for simplifying the display code - look for repeating bits of code. And use a switch statement.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
I think you’re guessing - how do you store something in an enum? If the task is to store a value into an array, then you’re way off track. Think simple.
OK, I'm working on this new task to develop a function which I think it could a function which receives pointers to other functions. That's my guess.

 

 

Did you really use 74ls47’s? I was ten years old when I last used them.

 Yeah absolutely! We have a lot of old chips on the components' compartments in the electronics store room in the college, they recently ordered EEPROMs! How about that?

 

That's why I used these old ICs because they are in stock and this is a good chance for me to use them. One of my mistakes when I wanted to get into electronics control projects is that I ordered the basic logic gates and similar ICs before actually getting an Arduino and other microcontrollers in general. And as a result those ICs are in my electronics box doing nothing! And then I started to work with the 74hc595 then I moved to the MAX7219 bare chips. Then I ordered the complete MAX7219 dot matrix breakout board.

 

So in regard to the college, I asked them to order a lot of Arduinos for the projects. And they listened to me so the current projects are done with Arduino boards which is a good thing for basic simple projects.

 

Then you’ve used an i2c expander. You like doing things the hard way.

 Yeah that was my decision for multiplexing, I thought it was a good choice and it's working now, I've used this module for other stuff in the projects; like, controlling 3-way traffic light system, and that saved us good amount of pins of the Arduino board. And here I'm multiplexing the 3 boards with one i2c expander.

 

As for simplifying the display code - look for repeating bits of code. And use a switch statement.

 OK, thanks for the advice.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Why are you guessing? I gave you the answer! I have no idea of why you are thinking about function pointers!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Mr Kartman,

 

 

I have a little problem with an IR and the 7-segment module.

 

The issue is that I'm developing a function which is based on people counting technology and I found that this technology is actually popular in systems which is required to count people in malls, centers .. etc.

 

My setup is simple, two IRs counting the entering and exiting states and update the counting on the 7-segment boards. The problem is when the IR detects the ACTIVE/LOW signal, the tens digit just go off!

 

It turns out that the reason is because of the flag register. Here's the code:

void IR_people_counting_set(void){
	if(!digitalRead(IR_1)&&(ir1_tri==0)&&(ir2_tri==0)&&(exiting_state==0)){
		ir1_tri=1;   // <--- This is the problem, when I comment the 7-segemnt
		             // 2nd digit works OK
	}

	/*if(!digitalRead(IR_2)&&(ir1_tri==1)&&(ir2_tri==0)&&(entering_state==0)){
		ir1_tri=0;
		entering_state = 1;
		IR_count_reset_start_millis = millis();
	}	

	if(!digitalRead(IR_2)&&(ir1_tri==0)&&(ir2_tri==0)&&(entering_state==0)){
		ir2_tri=1;
	}

	if(!digitalRead(IR_1)&&(ir2_tri==1)&&(ir1_tri==0)&&(exiting_state==0)){
		ir2_tri=0;
		exiting_state = 1;
		IR_count_reset_start_millis = millis();
	}*/
}

I commented the rest of the code because I was debugging the code.

 

 

 

==================================================================

 

Note: I'm not forgetting about your task to me which is to develop a function accessor to setup the time for any function in other libraries, but now because I'm working on the college projects which are obviously in Arduino coding.

 

But the task you asked me to do is for my own C multitasking project.

Last Edited: Wed. Dec 5, 2018 - 08:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I can see a reference to a flag but not a flag register. Why do you think the problem is in this code?
The problem I have is trying to make sense of your code - there is four tests of binary values so that gives at least 16 possibilities. Trying to map that out in my head is rather difficult. I would have to spend time with a pencil and paper to reverse engineer your code. Alternately, i could just re-engineer the solution. Apart from ‘solving’ your problem for you, you would not oearn anything. You have mentioned many times you wish to learn.
I dare say most of us here would draw a state diagram before even thinking of writing code. This forms documentation of how we expect the system to operate. We would then translate this into code. This is software engineering.

Your code has a handful of flags - the reality is only a small number of combinations of them are valid. I gather you can’t have both entering-state and exiting-state true at the same time. Mix in the other flags and the combinations multiply. Before long the average human brain cannot keep track of all of them and has got too complex. The art of programming is to make the complex simple.

Since i have little idea about how uou want your system to work, the following is my guess:
You have five states-
1. Idle. No sensors detected
2. Sensor 1 detected-enter
3. Sensor 2 detected-enter
4. Sensor 2 detected-exit
5. Sensor 1 detected-exit

You can have 1 variable to represent these 5 states. You then write the code to change between these states based on the inputs and time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The acessor function is one line of code in a function. Equally applicable in Arduino or C.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

This year's unbounded patience award awarded to Russell for heroic advice above and beyond the call of duty!
.
My favourite quote in this thread was the one about just writing what pops into the head. That, right there, is a perfect summary of why this thread will be interminable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about this code for the 7 segments boards.

 

void display_refresh(void){
	switch(digit_switch){
	ref_d_current = millis();
	if(ref_d_current - ref_d_start >= ref_d_pd){	
		case 0:
			ioexp8_write(0xFF,2);PORTB = (units1%10);ioexp8_write(0xFE,2);
			ioexp8_write(0xFF,2);PORTB = (tens1%10);ioexp8_write(0xFD,2);
			digit_switch = 1;
			ref_d_start = ref_d_current;
			break;
		case 1:
			ioexp8_write(0xFF,2); PORTB = (units2%10); ioexp8_write(0xFB,2);
			ioexp8_write(0xFF,2); PORTB = (tens2%10); ioexp8_write(0xF7,2);
			digit_switch = 2;
			ref_d_start = ref_d_current;			
			break;
		case 2:
			ioexp8_write(0xFF,2);PORTB = (units3%10);ioexp8_write(0xEF,2);
			ioexp8_write(0xFF,2);PORTB = (tens3%10);ioexp8_write(0xDF,2);
			digit_switch = 0;
			ref_d_start = ref_d_current;
			break;
		}
	}
}

 

But I can't increase the digits' brightness as running 1 board.

 

I think when I get into running more than one board the brightness should go down. That's why MAX7219 would be very useful in this application.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
This year's unbounded patience award awarded to Russell for heroic advice above and beyond the call of duty! . My favourite quote in this thread was the one about just writing what pops into the head. That, right there, is a perfect summary of why this thread will be interminable.

 

LOL .. Mr Kartman is really a nice guy, he has been very helpful for me since I got into AVR. I learned a lot in this forum, the people who reply to my threads .. I like how opinions are different, and how the gentlemen here points to related aspects of the code.

 

I just finished one of the projects I posted recently.

 

Here's the code, hope you like it!

 

The header file:

#ifndef ARDUINO_MULTITASK_H_
#define ARDUINO_MULTITASK_H_
#include <inttypes.h>

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// traffic lights 3-way project
#define SPEED_RADAR_IR1 A0
#define SPEED_RADAR_IR2 A1
// Red_Light_violation_IR
#define STREET1_RED_IR 4
#define STREET2_RED_IR 5
#define STREET3_RED_IR 6
// Red_Light_violation_Flash
#define STREET1_RED_FLASH 1
#define STREET2_RED_FLASH 2
#define STREET3_RED_FLASH 3
#define SAHER_SPEED_FLASH 0
#define RED3 7

/////////////////////////////////////////////////////
// initializations 
void pins_init(void);
void functions_init(void);
/////////////////////////////////////////////////////
// multitasking
void multitasking_manager(void);
// simple functions
void blink_pin13(void);
// Communication functions
void ioexp8_write(uint8_t data, uint8_t exp_no);
uint8_t ioexp8_read(uint8_t exp_no);
void speed_radar_set(void);
void speed_reset(void);
void traffic_lights_mask_write(void);
void red_set(void);
void red_reset(void);
void display_refresh(void);

#endif

 

The source code:

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include <Arduino.h>
#include "I2C_m.h"
#include "arduino_multitask.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// variables
static byte ir1_tri, ir2_tri;
byte masks[]={0xDE,0xDD,0xF3,0xEB,0x9B,0x5B};
byte red_light1_flag,red_light2_flag,red_light3_flag;
byte units1,tens1,units2,tens2,units3,tens3,digit_switch;
int8_t counter1,counter2,counter3,mask_cnt;
//static

// blink
unsigned long blink_st_ms;
unsigned long blink_cu_ms;
unsigned long blink_pd = 1000;

////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// IR speed radar set
unsigned long speed_1_time;
unsigned long speed_2_time;
// IR speed radar reset
unsigned long speed_reset_st_ms;
unsigned long speed_reset_cu_ms;
unsigned long speed_reset_pd = 2000;

// traffic_lights 3-way
unsigned long traffic_lights_st_ms;
unsigned long traffic_lights_cu_ms;
unsigned long traffic_lights_pd = 1000;

// red_light_counters
unsigned long red_cnt_st_ms;
unsigned long red_cnt_cu_ms;
unsigned long red_cnt_pd = 10;

// red_light_traffic_violation
unsigned long red_set_st_ms;
unsigned long red_set_cu_ms;
unsigned long red_set_pd = 10;

unsigned long red_reset_st_ms;
unsigned long red_reset_cu_ms;
unsigned long red_reset_pd = 100;
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Multiplexing 2 digit 7-segment with 74LS47
unsigned long ref_d_start;
unsigned long ref_d_current;
unsigned long ref_d_pd = 100;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// initializations
void pins_init(void){
	
	// 7-seg data lines
	DDRB=0xFF;
	//////////////////////////////////////////////////////////////////
	// traffic_saher
	pinMode(STREET1_RED_IR, INPUT);
	pinMode(STREET2_RED_IR, INPUT);
	pinMode(STREET3_RED_IR, INPUT);
	
	// speed sensors
	pinMode(SPEED_RADAR_IR1, INPUT);
	pinMode(SPEED_RADAR_IR2, INPUT);
	
	pinMode(STREET1_RED_FLASH, OUTPUT);
	pinMode(STREET2_RED_FLASH, OUTPUT);
	pinMode(STREET3_RED_FLASH, OUTPUT);
	pinMode(SAHER_SPEED_FLASH, OUTPUT);
	pinMode(RED3, OUTPUT);
}

void functions_init(void){
	digit_switch = 0;
	mask_cnt = 0;
	blink_st_ms = millis();
	traffic_lights_st_ms = millis();	
	red_cnt_st_ms = millis();
	red_set_st_ms = millis();
	ref_d_start = millis();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// multitasking code

void multitasking_manager(void){
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// sensors tasks
	blink_pin13();

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// traffic_lights tasks		
	speed_radar_set();	
	speed_reset();
	traffic_lights_mask_write();
	red_set();
	if(red_light1_flag||red_light2_flag||red_light3_flag)red_reset();		
	display_refresh();

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void display_refresh(void){
	switch(digit_switch){
	ref_d_current = millis();
	if(ref_d_current - ref_d_start >= ref_d_pd){	
		case 0:
			ioexp8_write(0xFF,2);PORTB = (units1%10);ioexp8_write(0xFE,2);
			ioexp8_write(0xFF,2);PORTB = (tens1%10);ioexp8_write(0xFD,2);
			digit_switch = 1;
			ref_d_start = ref_d_current;
			break;
		case 1:
			ioexp8_write(0xFF,2); PORTB = (units2%10); ioexp8_write(0xFB,2);
			ioexp8_write(0xFF,2); PORTB = (tens2%10); ioexp8_write(0xF7,2);
			digit_switch = 2;
			ref_d_start = ref_d_current;			
			break;
		case 2:
			ioexp8_write(0xFF,2);PORTB = (units3%10);ioexp8_write(0xEF,2);
			ioexp8_write(0xFF,2);PORTB = (tens3%10);ioexp8_write(0xDF,2);
			digit_switch = 0;
			ref_d_start = ref_d_current;
			break;
		}
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// traffic light 3-way MASKING/TIMIN
void traffic_lights_mask_write(void){	
	traffic_lights_cu_ms = millis();
	if(traffic_lights_cu_ms - traffic_lights_st_ms >= traffic_lights_pd){
		if(mask_cnt > 5) mask_cnt = 0;
		
		ioexp8_write(masks[mask_cnt],1);
		if(mask_cnt == 4 || mask_cnt == 5)digitalWrite(RED3,HIGH); 
		else digitalWrite(RED3,LOW);	
		
		if(mask_cnt == 2) counter1 = 4 * (traffic_lights_pd/1000);
		if(mask_cnt == 0) counter2 = 2 * (traffic_lights_pd/1000);
		if(mask_cnt == 4) counter2 = 4 * (traffic_lights_pd/1000);
		if(mask_cnt == 0) counter3 = 4 * (traffic_lights_pd/1000);	
		
		tens1 = counter1 / 10;
		units1 = counter1 % 10;  
		tens2 = counter2 / 10;
		units2 = counter2 % 10;  
		tens3 = counter3 / 10;
		units3 = counter3 % 10;

		if(counter1) counter1--; else counter1 = 0;
		if(counter2) counter2--; else counter2 = 0;
		if(counter3) counter3--; else counter3 = 0;

		mask_cnt++;
		
		traffic_lights_st_ms = millis();
	}
}


void red_set(void){
	red_set_cu_ms = millis();
	if(red_set_cu_ms - red_set_st_ms >= red_set_pd){		
		if((!digitalRead(STREET1_RED_IR)) && (mask_cnt>2) && (mask_cnt<=6)){
			digitalWrite(STREET1_RED_FLASH,HIGH);
			red_light1_flag = 1;
		}
			
		if((!digitalRead(STREET2_RED_IR)) && ((mask_cnt>=0) && (mask_cnt<=2))||((mask_cnt>4) && (mask_cnt<=6))){
			digitalWrite(STREET2_RED_FLASH,HIGH);	
				red_light2_flag = 1;
			}	
				
		if((!digitalRead(STREET3_RED_IR)) && ((mask_cnt>0) && (mask_cnt<=4))){
			digitalWrite(STREET3_RED_FLASH,HIGH);		
				red_light3_flag = 1;		
			}
		red_set_st_ms = red_set_cu_ms;	
	}
}	
	
void red_reset(void){
	red_reset_cu_ms = millis();
	if(red_reset_cu_ms - red_reset_st_ms >= red_reset_pd){
		if(red_light1_flag){
			digitalWrite(STREET1_RED_FLASH,LOW);
			red_light1_flag = 0;	
		}
		
		if(red_light2_flag){
			digitalWrite(STREET2_RED_FLASH,LOW);
			red_light2_flag = 0;
		}

		if(red_light3_flag){
			digitalWrite(STREET3_RED_FLASH,LOW);
			red_light3_flag = 0;	
		}
		red_reset_st_ms = red_reset_cu_ms;
	}
}

void ioexp8_write(uint8_t data, uint8_t exp_no){
  if(exp_no == 1)I2C_start(IOEXP1_WR);
  if(exp_no == 2)I2C_start(IOEXP2_WR);
  I2C_tx(data);     
  I2C_stop();
}

uint8_t ioexp8_read(uint8_t exp_no){
  uint8_t data;
  if(exp_no == 1)I2C_start(IOEXP1_RD);
  if(exp_no == 2)I2C_start(IOEXP2_RD);
  data = I2C_rx();
  Serial.println(data, HEX);
  I2C_stop();
  return data;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void blink_pin13(void){
	blink_cu_ms = millis();
	if(blink_cu_ms - blink_st_ms >= blink_pd){
		digitalWrite(13, !digitalRead(13)); 
		blink_st_ms = blink_cu_ms;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void speed_radar_set(void)
{
	if(!digitalRead(SPEED_RADAR_IR1) && (ir1_tri==0) && (ir2_tri==0)){
		speed_1_time = millis();
		ir1_tri=1;
	}
	
	if(!digitalRead(SPEED_RADAR_IR2) && (ir1_tri==1)){
		speed_2_time = millis();
		ir2_tri=1;
	}
	
	if(ir1_tri==1&&ir2_tri==1){
		ir1_tri=0;
		Serial.println(speed_2_time - speed_1_time);
		if((speed_2_time - speed_1_time)<1000)
			digitalWrite(SAHER_SPEED_FLASH,HIGH);
	}
}

void speed_reset(void){
	speed_reset_cu_ms = millis();
	if(speed_reset_cu_ms - speed_reset_st_ms >= speed_reset_pd){
		ir2_tri=0;
		digitalWrite(SAHER_SPEED_FLASH,LOW);
		speed_reset_st_ms = speed_reset_cu_ms;
	}
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I can still see repeated code.

 

As an aside, for a simple project, then the code might be acceptable. For a real world application, the code is unacceptable - it expects a fantasy world where everything works. 

One of the first lessons in programming is GIGO - garbage in, garbage out. Simply put, if you feed the program garbage, then you'll get a garbage result. In relation to your code, you read the input bits and expect that they represent the true current state of the real world. The reality is that this is not always true. There's ESD, EMI, interference from fluorescent lights and so on. When you read a port bit or adc, it is a snapshot of the input for a small period of time. This snapshot could be a transient, thus your code will make the wrong decision based on faulty data.

 

How do we resolve this?

 

The more times you read an input, the more likely you will have a better representation of the true state. You can average or filter the data. It's basically the same as debouncing. You can also factoring in knowlege of the input. For example, if you had a door switch, you might know you can only open/close the door so many times per second. If you measure more than that, then the input is faulty. Another example might be a limit switch - because it is mechanical, then it makes sense to only do something if the input has been active for a given time. This is probably 10's or 100's of milliseconds. Anything else is a transient.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the reply.

 

 

OK, now I have two questions regarding your evaluation points.

 

1. Could you point to me the repeated code so I can work on that?

 

 

2. The second question:

10's or 100's of milliseconds. Anything else is a transient

So do you mean that I should record the period to an input signal to be between 10's up to 100's of ms?

 

For example, I can develop a function which takes any input signal trigger and this triggers a "for loop" to run like 100 times and reading that input signal and count the ACTIVE LOW/HIGH signals, so if the count is above certain number then that is an input signal?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

1. That's your job. 

 

2. "It's basically the same as debouncing." you've been pointed to the relevant documents before.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

1. That's your job.

 

Is it the 7-segment function?

 

2. "It's basically the same as debouncing." you've been pointed to the relevant documents before.

I actually have been pointed to different information sources. Could you tell me which ones? Sorry ..

 

Were I pointed to them in this thread or in another one so I know which thread to check? 

 

 

===============================================================

 

But I'm really happy that I reached a level where I can write a code that could considered to be OK. I have the problems of securing the input reading functions so I don't get mistaken signals that are caused by ESD or EMI.

 

So, I think if I improved the repeated 7-segment and input reading functions, then this code could be a good one in regard to the application it's running.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I don’t consider the code ‘ok’. It needs more work in the design and implementation. I’ve given you hints, so don’t keep asking the same questions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
I don’t consider the code ‘ok’. It needs more work in the design and implementation. I’ve given you hints, so don’t keep asking the same questions.

 

OK, I'm taking your evaluation for my coding into consideration, while I thought the code is really organized and good but it turns out it's not good in the real world and your comment is inspiring, it enforces me to think how the code is very very basic, doesn't have optimized coding style. So thanks Mr Kartman I want to improve the code but I think I need to deep in more into how things should work and how a good code can be effective and secure in a real world environment.

 

Last Edited: Fri. Dec 14, 2018 - 12:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

‘Crab reports’! The term is ‘crap’ which is short for crapper which is a reference to Thomas Crapperwho invented the toilet as we know it today. Thus if we say something is crap, then it is suitable for the toilet, ie: shit or not very good.

Why do you ask our opinion? We’ve given it many times but you’ve steadfastly ignored it. Thus you’re not helping your cause and being disrespectful to us as well.

Since you have no idea of programming, why don’t you start your learning with that. Programming is not coding. Writing code is the last step of the process. I’m talking about the concepts of decomposition (divide and conquer) , abstraction and flowcharting. These are fundamental concepts and can be introduced in a couple of lectures. Then move into binary numbers and Boolean logic. Then onto the basics of computers. Then onto the basics of a programming language (such a C) and how you can express program logic using it. There is a wealth of online information you can draw from.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take a look at this thread:
https://www.avrfreaks.net/forum/external-interrupt-20
It’s an example of poorly constructed code. There was no decomposition of the problem and definitely no abstraction. The code is just a string of statements with lots of repetition. To make any changes will require extreme mental gymnastics. The poster is having troubles, but hedoesn’t quite understand the web he weaved with the code and therefore the actual problem maybe not what he thinks the problem is.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
‘Crab reports’! The term is ‘crap’ which is short for crapper which is a reference to Thomas Crapperwho invented the toilet as we know it today. Thus if we say something is crap, then it is suitable for the toilet, ie: shit or not very good.

Sorry didn't know that this word return to toilet. I thought I means garbage. I meant the reports aren't as little professional as I wanted to be.

 

 

Why do you ask our opinion? We’ve given it many times but you’ve steadfastly ignored it. Thus you’re not helping your cause and being disrespectful to us as well.

Believe me, I have no intention to ignore or disrespect any of you or the members advices and opinions, it's just take me time to get to that point, sometimes it's easy and I can do it quickly; for example, the multitasking as it a very difficult topic to me but took little time with the help of your thread so that was nice.

 

And the accessor function which I still don't know what to do about, you mentioned that it has nothing to do with function pointers. But I'm still moving around this title, I'm sorry but I have no clue to do the accessor function.

 

Since you have no idea of programming, why don’t you start your learning with that. Programming is not coding. Writing code is the last step of the process. I’m talking about the concepts of decomposition (divide and conquer) , abstraction and flowcharting.

I can do something of that like the projects in this semester, 3 projects were my idea, 1 was the department chief. The project design, programming and implementation were all done by me.

 

But for example, if I taught the students the flowchart of the project and told them to do it in code, then that would nothing for them because they have no idea how to implement that flowchart into a code.

 

 

These are fundamental concepts and can be introduced in a couple of lectures. Then move into binary numbers and Boolean logic. Then onto the basics of computers. Then onto the basics of a programming language (such a C) and how you can express program logic using it. There is a wealth of online information you can draw from.

I really liked you order or dividing of how to introduce the topics, but I don't know, I don't they can grasp these basics in an order of like 6-8 lectures. Because our lectures contact hours is little. So for projects they attend 6 hours in a week, it sounds like enough but it isn't because like this semester it was in one go from the 8 am to 12:30 pm, and they need to get 1 hour break and come back and their attention may get distracted.

 

At the beginning of this semester I tried to instruct them to do simple things but I realized if I continued to work on the basics each week then the semester is in the middle and the time is running so I told them to just do the wiring and I do the programming.

 

Another example, is like the flags variables, how to set and clear them is a difficult topic for them to do.

 

I can teach them the basics of C, but asking them to do anything by themselves would difficult because code design of something is really hard, because I myself went through a lot to learn how to design simple functions.

 

I don't know what to do the next semester! But I can use my experience in this semester and ask the department to lower my hours so I have more time to work on projects and also to do some tutorials. I'm thinking to improve my process to force the students to do some programming, how?! I can prepare simple examples and enter that as a task for them to modify and develop another one.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Take a look at this thread: https://www.avrfreaks.net/forum/... It’s an example of poorly constructed code. There was no decomposition of the problem and definitely no abstraction. The code is just a string of statements with lots of repetition. To make any changes will require extreme mental gymnastics. The poster is having troubles, but hedoesn’t quite understand the web he weaved with the code and therefore the actual problem maybe not what he thinks the problem is.

 

I took a look at that thread and copied the code! wow it's 500 lines and it was really difficult to follow the code procedural order!

 

I learned things that when I post a thread that I think and believe that I'm understanding my issue and wanting the others to understand my issue and help me as the thread or the code is not clear enough.

 

To me, helping others is really a difficult job, I have to be really very experienced with a lot of programming aspects and horizons. Programming is a huge world!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The idea of education is to teach the tools the student needs to solve the problem. Trying to fast track your students by having them solve problems you havent given them the tools for is folly. The evidence is in your code!

Your comments on the other poster’s code confirm this. Its easy to see the process in that code, but there is a lot of repetition of the keypad code. The concept that was not applied was ‘abstraction’.

Last Edited: Fri. Dec 14, 2018 - 10:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
The idea of education is to teach the tools the student needs to solve the problem.

 

But motivation is also an important key in education, what I have in this semester from students' interest in:

 

1. Microcontrollers course out of 40 students is the follows:

6 shown interest in some of the logics in microcontrollers and programming in general

6 shown interest in their marks

 

Rest in divided into two groups:

Group1: wants to pass the course

Group2: Don't care.

 

2. Projects course out of 18 students:

I divided them into 4 groups, hmm I can't judge them exactly whether to measure their interests in projects with microcontrollers but I can say they mostly enjoyed doing the projects but their main problem is lack of knowledge in electronics parts and modules because it's their first experience with most of the parts used in the projects. The next problem is also programming.

 

It isn't their problem and I don't blame them, it's just I'm thinking of a way to improve the situation. I know I lack the necessary skills to teach the students in a faster way and effectively. I'm of course part of the problem, I need a lot more experience to improve myself.

 

 

Trying to fast track your students by having them solve problems

That sound interesting! But how to do that?

 

you havent given them the tools for is folly.

At the start of the semester I asked them to look for the parts we have and get their codes, but it didn't work very well, they don't have a direct goal of which code to look for and how to use it.

 

For example, the group which has the traffic system project. At first I told them how to do masking bits for 3 traffic light, red, green and yellow. Then 6 and after that 9 traffic lights for 3-way road and that's it! They didn't know how to move from there.

 

Another example, is the greenhouse system, I told them what we want to control and how, but also the same problem.

 

 

The evidence is in your code! Your comments on the other poster’s code confirm this. Its easy to see the process in that code, but there is a lot of repetition of the keypad code. The concept that was not applied was ‘abstraction’.

Yes abstraction is a very good strategy. I should also learn how to increase my level of improving the 'abstraction' in my code.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

WAIT! You are the teacher? $Deity help the students.

 

What teaching qualification do you have? What other qualifications do you have?

Ross McKenzie ValuSoft Melbourne Australia

Last Edited: Sat. Dec 15, 2018 - 02:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
setTaskTimer(uint8_t task, uint32_t time)
{
    if (task < NUM_TASKS)
        {
        task_timers[task] = time;
        }
}

An accessor function. Otherwise known as a 'setter'. You wanted to know how to access task_timers from other modules. This is how. No function pointers. I have no idea of how you made such a simple function so complex you couldn't write it.

 

We could put some ASSERTs in there as well.

 

 

Two books - Code Complete and Writing solid code. I've mentioned these to you at least once before. Read them. Understand them. Then you wont need to ask me questions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

WAIT! You are the teacher? $Deity help the students.

 

What teaching qualification do you have? What other qualifications do you have?

 

LOL I read you comment first when I woke up :)

 

Yes, I'm an electronics trainer along with hundreds of other trainers like me. I'm actually not an electronics or programming guy. It's mostly a job opportunity and I went into the flow.

 

The story is that our technical educational organization in Saudi Arabia wanted to implement more trainers because it has a lot of colleges and institutions in different cities and villages. So it developed a new college in an old college building and named it Technical Trainers College TTC which ran by a German organization call the GTZ and the name changed to GIZ, this is the company description  from Google:

German development agency headquartered in Bonn and Eschborn that provides services in the field of international development cooperation.

The college now is run by another british company and they changed the name of the college to be applied engineering college AEC, this is their website:

http://www.appliedengineeringcollege.com/

 

 

So my story is that I was looking for a good job opportunity in my life and I was working in women fashion store and I was like 27 yo, so you can imagine I was already 27 yo and don't know anything about electronics. And one of my friends told me to go and register in the electronics and telecommunication college and I did and they accepted me and it was one of the biggest happy moments in my life. And then I got the diploma in electronics from this college.

 

Then after graduation I went to immediately to another college which is the TTC which provides bachelor in training in electronics and the study was %60 on vocational pedagogy which were new and good courses, and %40 in electronics which were poor courses, because the teachers of electronics are from anywhere in the world but I don't know why they didn't know a lot about electronics. I think they are specialized in other things and taught us courses not in their interest. Teachers of training courses were kind people.

 

I had two programming courses in that college:

1. in C++ which was about how to do multiple "cout" commands.

2. Microcontrollers: which was the PIC16F84A, and I learned almost nothing in that course, it was in assembly. Maybe I learned something but it was very very little.

 

That's all, I have diploma in electronics and bachelor in training. I'm now 36 and struggling in getting into the basics of programming. But I loved electronics since I got into the diploma degree.

 

And now in the college I work at, I train the only two courses which deals with microcontrollers. That's why I'm trying as much as I can to learn something in programming everyday. Hope you like my story :)

 

I wrote my story because I want you guys to understand the background I have in electronics and programming in general.

Last Edited: Sat. Dec 15, 2018 - 06:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is really sad.

 

I went to Jeddah as the Instrumentation Adviser to the Director of Instruments at MEPA (Metorology and Environment Protection Agency) in 1982 on a 2 year contract, but stayed 5 years. Although holding an Electrical Engineering Degree from a Saudi University, Jamal didn't even know what a transistor was. So I can completely understand how you have managed to get yourself in this unenviable situation. Any technical qualification gained in Saudi is worthless in my admittedly dated opinion/experience. In the late 70s, dozens of Saudi high school graduates were offered the opportunity to become engineers by attending courses in the UK run by International Airradio Limited under the City and Guilds guidelines. Only one came back with anything like a respectable degree and only because he was bright and "escaped" to a real university. The whole scheme was a swindle in my opinion. I even had to intervene and demand the repatriation of Filipino staff who could not even solder or read a resistor colour code. I did this for their own protection.

 

Sad. Really sad.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Regardless of the state of the Saudi education system, educating oneself is easier than ever with free online courses in programming and engineering.  Even our universities are churning out graduates that are next to clueless. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

That is really sad.

 

I went to Jeddah as the Instrumentation Adviser to the Director of Instruments at MEPA (Metorology and Environment Protection Agency) in 1982 on a 2 year contract, but stayed 5 years. Although holding an Electrical Engineering Degree from a Saudi University, Jamal didn't even know what a transistor was. So I can completely understand how you have managed to get yourself in this unenviable situation. Any technical qualification gained in Saudi is worthless in my admittedly dated opinion/experience. In the late 70s, dozens of Saudi high school graduates were offered the opportunity to become engineers by attending courses in the UK run by International Airradio Limited under the City and Guilds guidelines. Only one came back with anything like a respectable degree and only because he was bright and "escaped" to a real university. The whole scheme was a swindle in my opinion. I even had to intervene and demand the repatriation of Filipino staff who could not even solder or read a resistor colour code. I did this for their own protection.

 

Sad. Really sad.

 

Yes, that's actually the situation. It's about the education system, besides that the 3 schools any Saudi should go, elementary, intermediate and secondary, it's moving thousands of students and the loads are high and it's a pressure on the teachers, that's why they just push the students to the next level as when the student graduates from high school, he whether go to a technical college, a university or to the army.

 

But another important reason is that Saudi Arabia doesn't engineer anything, so basically an engineering college or university is just simple to intermediate laboratory exercises, and maybe advanced experiments. But anyway I can't evaluate more details in universities education because I don't have the background about that.

 

Now our technical educational organization is moving to replace all the foreign teachers who hold masters to PhD degrees teaching basic technical courses with Saudi men, and it has replaced now almost all the foreign teachers with Saudi undergraduates whose having a bachelor, masters or PhD degrees from any college or university in technical or general studies.

 

But what's the problem now in our diploma programs whether they are in electronics, networking, mechanical or electrical technologies. Our colleges are technical colleges, so it's not engineering colleges. So the courses are basics of the basics in the specific technology, e.g. electronics. So in electronics department, the courses are really basics of that topic, whether it's basic DC fundamentals, logic ICs, electronic circuits, PLC, microcontrollers, control system .. etc. I won't judge all of that but the level of information in these courses is really simple nothing advanced.

 

For example, in logic ICs, they learn the truth table of logic ICs, AND, OR, XOR, ... etc. In the lab, they do the simple exercises of the basic gates and that's it! There's no more like advanced circuits with the logic gates, so the student pass that course just know the IC, but now it's really important in life.

 

But as I mentioned before, I don't blame them because I was in the same level as them. So if they don't know anything about programming, then it's not their fault. And also programming is a new topic in the diploma programs. Other colleges don't train microcontrollers programming in C. When I came to this college they were working with flow code. And this semester I told them I want to work with mikroC and they agreed to my request. But I don't want to push things hard to students because programming would be hard for them to do, so asking them to develop a simple function would really really difficult. So I just post the code on the projector and they just copy it to the IDE and build the program, it's very basic situation.

 

Overall, it's OK for me, because programming in C or C++ isn't official in the diploma programs. The microcontrollers course isn't a problem to me, because they just have to copy the code for a simple blink program, but the problem is in the project course where they have to program a complete project by themselves. So where they don't know how to program, then it was my job to write the code for the 4 projects in this semester, it's OK but I really want the students to do the programming so they learn something.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

Regardless of the state of the Saudi education system, educating oneself is easier than ever with free online courses in programming and engineering.  Even our universities are churning out graduates that are next to clueless. 

 

That's the spirit Mr Kartman, thanks for encouraging me and of course helping me a lot in this forum :) I now just have to get back to my libraries, I've decided to start working on TFT displays' libraries, so I'm started looking into datasheets for the model I have, and yeah, since programming a TFT would more advanced thing than the sensors or the modules I worked with, I hope to learn a lot.

 

But now I have to finish the function accessor task, then I move on to TFT library development.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you not listen to a single thing I said?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I've asked to enhance one of the projects of the last semester, the one about building control, the one is #55 2nd one on the left.

 

The design isn't aesthetic as it should be, and also the chief of our organization is coming for a visit, and the department wants me to do the necessary modification to this project.

 

They don't know about the code, but we here know that the code needs more improvement.

 

I'm trying today to improve the trigger of the IR signal. As Mr Kartman mentioned it needs more approvement of registering a trigger.

 

I'm now working on this snippet:

 

uint8_t count,i;
void setup() {
Serial.begin(9600);
DDRB = 0x21;
DDRC = 0x00;
}

void loop() {

  if(!(PINC&(1<<PINC0))){
    for(i=0;i<50;i++){
      if(!(PINC&(1<<PINC0)))    
        count++;
    }
  }

    Serial.println(count);
    count=0;
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
    for(i=0;i<50;i++){
      if(!(PINC&(1<<PINC0)))    
        count++;
    }

The timing of the sampling in this loop is completely arbitrary??

 

You said " trigger of the IR signal " so I guess we can expect some well known IR protocol like Philips RC5 ? If so then the timing of the pulses is well known. The detection of such pulses is also a much repeated experiment in internet code. In 2019 no one should really need to be reinventing this particular wheel.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The timing of the sampling in this loop is completely arbitrary??

Yeah I agree, I think it would run the for loop each time the pin is triggered. I thought the for loop is mandatory like the while loop, so I thought to run 50 cycles and count the number of preceding input pulses for assertion purpose.

 

You said " trigger of the IR signal " so I guess we can expect some well known IR protocol like Philips RC5 ?

 It's this one:

 

 

 

This one only detect any obstacles in front of the module with active/low signal, but reading it with the Arduino is really fast of course and; for example a normal obstacle like a person would trigger 50-100 and more for one trigger.

 

Mr Kartman suggested for me a more trigger proof method for detecting the signal.

 

The method I'm using in my code applying flags for any trigger, so that prevents the preceding input reading problems. This snippet:

void ir_people_counting_set(void){
	// First, detect any trigger to IR1 - entering building
	if(!digitalRead(IR_1)&&(ir1_tri==0)&&(ir2_tri==0)&&(exiting_state==0)){
		ir1_tri=1;
	}
	// The completion of registering input signal
	if(!digitalRead(IR_2)&&(ir1_tri==1)&&(ir2_tri==0)&&(entering_state==0)){
		entering_state = 1;
		ir_count_reset_start_millis = millis();
	}	
	
	// Second, detect any trigger to IR2 - exiting building
	if(!digitalRead(IR_2)&&(ir1_tri==0)&&(ir2_tri==0)&&(entering_state==0)){
		ir2_tri=1;
	}
	// The completion of registering exit signal
	if(!digitalRead(IR_1)&&(ir2_tri==1)&&(ir1_tri==0)&&(exiting_state==0)){
		exiting_state = 1;
		ir_count_reset_start_millis = millis();
	}		
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The above is a prime candidate for a finite state machine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you so much Mr Kartman, that's a huge compliment for me, I actually done all the projects last semester with similar strategy and flags is very effective I was able to control the program and what to run and what to halt.

 

So, this method is better than debouncing input signals, is that right? Is there something I can do to improve this function?

 

Running the projects, it actually ran pretty well, not much hangings or stucking in the loop of the program, it worked ok. But still there are other flaws in the project hardware as well. That 2 digit 7-seg board has some problems with displaying numbers if it worked along with a LCD1602 .. I don't know why. The wiring isn't my work, it's trainees work, they believed they did it well, but I have some doubts. I have to redesign that project anyway.

 

I can't ask maquete people to do it for me because they are so expensive and the department doesn't any reasonable money for projects, but I and other new trainees of this semester are planning to redesign it again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wolfy - don’t respond with more questions until you’ve done some research into what I have suggested. Start with googling state diagram. Then get a pencil and paper and draw yourself a state diagram of the above code. Then re-write your code as a finite state machine. Using flags does not scale well. Once you’ve got beyond 3 or so flags, to code gets messy and hard to understand. Using a state machine simplifies this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello guys,

 

It's the 2nd semester of this year, and in this course, we are working on the same previous 4 projects + new sub projects because the group this semester is like more than 30 students.

 

I'm searching for projects' ideas and designs, but medium to beginner level projects, as I can't work on modules that I have not master yet.

 

So, I was searching on this website, and came across this project, I liked that idea as I like the industrial application projects, to domestic level projects that serve the community .. etc.

 

This project uses PIC microcontrollers, it doesn't matter because we have both Arduino boards + some PIC16F877A chips. This is the link:

https://electronicsforu.com/electronics-projects/wireless-gas-detection-monitoring-system

 

This project uses some respectful high end RF modules which costs 22 pounds. So I thought to take the project idea and change the controller and the RF modules for bluetooth modules.

 

My questions here are:

1. Any comments or ideas for me to add to the project.

2. More similar project examples you guys have for industrial applications.

Pages