How to make a right flow chart this code

Greetings,

I'm sorry if this is not the right forum to ask this question, it would be much appreciated to redirect me to another forum appropriate for this post, so I thought at first that I understood how to make a flowchart for my Adruino code until today I have failed an exam for my project miserably, apparently, I did not follow any rules on how to make a flowchart, the professor was vague and unclear about what I did wrong,

I would appreciate it if someone could show me how a flowchart of the code below must be.
Note: What I'm to achieve by writing this code is post pressure and temperature on the LCD I2C and send data of ( Temperature/Pressure as well as approx Attitude though Bluetooth (TX/RX) to display it in a simple Android app that I made using MIT inventor and everything worked well ( I just want to point out this that I'm asking about the code working or not It's just the flowchart that keeps bugging me.

The code :


#include <Wire.h>             
#include <Adafruit_Sensor.h>  
#include <Adafruit_BMP280.h>  
#include <LiquidCrystal_I2C.h>   

#define BMP280_I2C_ADDRESS  0x76

Adafruit_BMP280 bmp280;

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 

void setup() {
  Serial.begin(9600);

  lcd.begin(16, 2);
  
  Serial.println(F("Arduino + BMP280"));
  
  if (!bmp280.begin(BMP280_I2C_ADDRESS))
  {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }

  lcd.setCursor(0, 0);
  lcd.print("Temp:");
  lcd.setCursor(0, 1);
  lcd.print("Pres:");
}

char text[14]; 

void loop()
{
  
  float temperature = bmp280.readTemperature();  
  float pressure    = bmp280.readPressure();     
  float altitude_   = bmp280.readAltitude(1013.25); 


  sprintf(text, "%d.%02u%cC  ", (int)temperature, (int)(temperature * 100)%100, 223);
  lcd.setCursor(5, 0);
  lcd.print(text);

  sprintf(text, "%u.%02u hPa ", (int)(pressure/100), (int)((uint32_t)pressure % 100));
  lcd.setCursor(5, 1);
  lcd.print(text);


  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Pressure    = ");
  Serial.print(pressure/100);
  Serial.println(" hPa");

  Serial.print("Approx Altitude = ");
  Serial.print(altitude_);
  Serial.println(" m");
    
  Serial.println();  
  delay(2000);      
  
}

Haven't you got this back o front ?

If you are going to use a flowchart it would be more normal to draw it before writing the program.

It is almost as if you found the code somewhere but need a flowchart as part of an assignment. The code uses some fairly complicated program statements and if you are capable of writing them I would expect you to be able to draw a flowchart

For instance

sprintf(text, "%d.%02u%cC  ", (int)temperature, (int)(temperature * 100)%100, 223);

what does each part of this line of code do ?

To follow up on heli, we have the ability to assist in making a flowchart. For me personally, its one of my favorite parts.

It all starts with a thorough understanding of the code that you wrote.

If you're trying to flowchart someone else's work, it becomes much more difficult.

Once you're able to understand your code, a flowchart is as easy as trying to explain your program as a whole, in plain English. There should be a start, an end, and arrows pointing the reader along the way. Start/end are ellipsis, decisions are diamonds, data tends to flow from left to right, top to bottom.

I'll see if I can find the flowchart I made for my design project a few years back.

If you need a flowchart program, I like Microsoft Visio. If you need a free one, draw.io

We could be less vague and more help if you shot us a picture of the flowchart you made and your teacher didn’t like.

a7

Sure my bad, I hesitated to post my flowchart since all my work is in French I tried to translate as much as I could .

Flowchart :

I kinda did get right what you just mention but apparently according to my professor it is completely wrong, as @alto777 asked to post my flowchart, here is mine, it is in French I could have done some mistakes while translating

Well I am no flowchart expert, I draw things that work for me that sorta kinda a little bit adhere to some conventions and standards.

But. In no way is your flowchart "completely wrong".

The labels in the trapezoid shapes are not usually shown as blocks in a flowchart. I do not know the proper way to add labels to a flowchart that are meant to be a guide to the source code. I'd just delete the trapezoid blocks.

There are a few stray "oui"s: blocks that do not have multiple output lines don't need "oui" or "non" on the single output - that's the path that is going to get taken no matter.

Outside of getting really picky, which would be wrong of a teacher who didn't actually try to teach you how to make a flowchart, I don't see anything wrong.

Your flowchart describes all the code and the steps that make it up.

I would love to see the flowchart the teacher expects you to have drawn…

Get the teacher to show you, or direct you to where s/he thinks it might be a good idea for you to waste spend time learning.

Google "basic flowcharting" or similar, pick some plausible website and learn someone's idea of how a flowchart should look. I don't think you are that far off.

I'm neither an expert nor a huge fan of flowcharts for program development. Diagrams have their place. For logic and code structure, I usually "sketch" my programs not yet written in so-called pseudo code, viz:


HTH

a7

1 Like

Alright thank you, I have a question, should I replace the trapezoid blocks with a rounded rectangle or just keep everything rectangle?

I'll guess the block shape is not that important.

I can think of two possibilities.

  1. It lacks small specific details. By the way your flowchart doesn't show where you call the library to read the sensor.

  2. You didn't include the library flow.

Below is part of a flowchart I made for my own project.

BTW you should ask your instructor to expand on "completely wrong"

Good luck

Alright, I apologize i am on my cell phone so i may need my laptop later!

First thing is first, of your program has a start in an ellipse. Good start!

Going through your code snippet, your start should lead right into your initialization block (shape is a trapezoid).

So we have ( Start) -> /initialization/

From the setup trapezoid, have an arrow come out towards the RIGHT OF the initialization trapezoid.

This will be a square block, starting your process of initializing the LCD. This block then leads into your "Setup"

The "Setup" SQUARE block is starting serial, setting the address, writing the LCD, and leads to a decision diamond of "Is the bmp sensor connected" (yes or no)

Let's take a shot at this and see what it looks like when you've got an update!

Please let me know if anything is unclear :slight_smile:

Edit: remember that your goal of a flowchart, is to easily describe the flow of the process logic. This is an overview / pseudo-code.

This is the setup loop, and main loop block of a previous project. You should be able to follow it

1 Like

Shape is vitally important to the professor.

As important as syntax to a program.

Did you fail because yourcode and flowchart were not exactly matched?

Both could be perfect but not match.

.

1 Like

Get a different teacher?

Flowcharts? Really? I've not used one of those since the early 1980s.

-jim lee

2 Likes

I use them regularly. In one recent program, inspecting the flow allowed me to see a better way to approach the issue and was able to reduce my code complexity.

Curious, how would you approach an imbedded code project?

2 Likes

I work as an SME and I can guarantee any product that my company sells is UL certified, and require appropriate flow charts.

Signal flow, APN mapping, product function, embedded function, encryption, blah blah blah, anything IOT, testing, debugging, the list goes on

Flowcharts are needed. Especially ones that don't get laughed out of the room! I had a professor that made the class a living hell.

I've used damn near every topic brought up

Maybe different people just think differently. I was taught flow charts in the.. 70s? Then, by the early 80s, I found that just writing code in "human" (top down) worked a LOT better for me. For me flowcharts just make things more confusing. On any project that's large and daunting, I would start with the user manual. Once a detailed user manual was written, the code itself was just a matter if typing.

-jim lee

flow charts are like comments, but in a broader sense.
if you need a team of people or if the code will take weeks, it offers reference points.
it also allows one to simple work out how things can be done.

but, in class, the teacher should have given you what each symbol means for the class.
is there a symbol for readout on a display ?
is there a symbol for serial out to your monitor ?
what symbol does the teacher expect for I/O ?

is there a symbol showing the start of a loop ? and an end of the loop ?

you use a trapezoid for 2 totally different things.
initialize is printed in the first one
setup is printed in the second followed by a rectangle that says initialize

display at the end of loop, should be a different shape. all the shapes should have been given to you by your teacher. and somewhere he should have given you an example.

1 Like

Hi, @tikolord
This chart might help;
guidetoflowchartsymbols_mostcommonimg

Tom.. :smiley: :+1: :coffee: :australia:

1 Like

I am not able to follow it. Perhaps the OP will not bring any experience or prejudice to his examination of the example you provide and follow it just fine. I cannot.


That's funny. My first reaction to your pile of variously interconnected symbols was to, basically, laugh it out of the room.

I srsly considered that you might be having us on. But it appears you are serious.

I have just now perused a few pages of flowchart pictures, several dozens. I saw nothing like your flowchart…

Please do not explain it to me. Rather, tell us from what flowchart school / style / philosophy / book did this kind of thing come from? I am quite curious.

I have never had to create a flowchart for a teacher, an employer or a colleague. My own flowcharts, such that I make, are undeniably non-standard to the point of being quirky. But I am quite sure that almost any of them could be "followed" just fine.

I can't let @tikolord go away thinking thst flowchart is normal at all.

a7

It's all good, I am here to assist where I can. If you cannot follow the flowchart, that is fine. It is not a simple one to follow and I apologize for insinuating it was.

As far as the original post, hopefully everything posted helps move them forward.

Using the standard symbols (How to make a right flow chart this code - #18 by TomGeorge) you should be able to describe how the program works. In plain language.

In addition, the oval "terminator" can be used to initiate "loop" and "setup"

I have to wonder if the class discussed flowcharting and you missed it?
(I'll be the Professor is over 60)