I want to know if my code is well written

There are lots of people who want to help a newbie. We don't want to help the robot.

Again, if you have some specific question then ask away and get answers. But "is this code well written" is a BS question to begin with. It sounds like you are having some trouble with it. A better question would have been to explain what it was supposed to do and what it really did and ask how to fix it. Nobody wants to read through robot code to try to spot the mystery problem.

Please. You came in here and completely ignored the posts explaining the rules and etiquette here. You expect things to be done YOUR way otherwise we are toxic. You're simply wrong. In reality you're just another example of the same toxicity that we've been getting from people who don't understand why they'd actually have to try and fail and learn to write code instead of just having it magically appear to make sense.

No it couldn't. You haven't given me enough information to help you. You asked a vague question about some robot produced code with no indication of what the actual problem was.

One important thing to think about when you're looking for someone, is not to just walk up and expect that they are going to put out for you. At least try to respect the culture of the place you're walking into a little. You'll find that people are friendlier when you're not trying to dictate the terms.

We get that a lot, mostly when we don't do someone's homework for them, or don't solve someone's problem for them. Some people have certain expectations as if they'd somehow paid us or something and we owe them. I'm not sure where that comes from. They feel we owe them and then think we're mean if we don't put out for them.

If that was the first thing you thought when reading my question, it says a lot about you.
If it's not the best way to express yourself, you could have told me and continued there.

What rules were I ignoring?

i did, I just wanted to know if the code successfully generated a frequency sweep and read data.
Imagine that I would have preferred a simple "yes" or "no" as an answer.

what does that mean??? If I'm new to something OBVIOUSLY I won't know what "culture" this platform has...
Should I study your culture first?
This is a forum where anyone can ask something "no matter how wrong it is"... if you don't like the answer or if you think everything you thought you simply wouldn't have written anything.

Now if you commented on my post, it means you want to help me... but there are thousands of ways to let me know how to move forward...

What "respect" are you talking about? the one I'm not having?

No, you asked if it was well written.

Imagine you were an aspiring author and you were tasked to write a spy novel. What you wrote was "Little Red Riding Hood". And then you go on an author forum and ask it if is well written. Well, for a children's book sure. For a spy novel maybe not. But just as a vague general question how can you answer that.

That's not a question for me. I don't have the thing built in front of me. Put it together and test it. That's the only way you know if it does what you want.

It is true that ChatGPT can write some really good code, but it takes a coder to know how to ask. You can't pull that off if you don't understand what it's giving you back. And when that's where people are at then there is little that someone like me can do to help. You've basically fallen into a trap. I've seen lots of people in this same trap. I have experience with this trap. If you want out then spend some time learning the language, start with simple examples, ask for help here. If you want a fast track to the answer with the least amount of work, then keep banging your head against the wall with the robot.

It's not that I'm refusing to help. There's no help I can give you if this is where you are at. You've got some robot written code that you are ill equipped to understand. What help can I offer except to let you know that you've started backwards and fallen into a trap with ChatGPT.

Okay bro... ill go with my BS question to another platform, but no before learning about the culture....

Because if i dont do that the people there are gonna have their egos hurt...

Who has their ego hurt? I'm just explaining to you why nobody liked your question. Nobody's ego was hurt. You're the one with the attitude walking away.

Again, if you have any specific questions about this code or how it works then please ask them.

I'ma put you on ignore though. You're obviously more worried about arguing about what you think you are entitled to here.

I just wanted to ask something, but you guys made a big deal out of it. I repeat, if my question was not what you are USED TO just let me know without this big fuss....

pd: your comment about "culture" was very good LOL

If you want to learn how to write the code, people will help you. Start, step by step, for example, write the code which controls AD9833.
ESP32 ADC needs to read 20Hz to 20KHz sweep, from the output of the filter you are testing? If that is the case, ESP32 internal ADC is not adequate.

Look for Teensy mcu .

As what should be an obvious starting point, to accurately capture a 20kHz sine wave for analysis, the A/D sample rate has to be AT LEAST 40kHz, rather than the 10Hz sample rate in the existing code.

And a 200-sample capture buffer is useless for any frequency below 100Hz.

Thanks for your answer!

I have already controlled the ad9833, I have also had success in performing the frequency sweep and I have done my previous research previously.
The idea is to perform a frequency sweep and with each frequency increase read a voltage value at the output of an audio filter, let's say it as follows...

generate a 100hz signal --> read voltage
generate a 200hz signal --> read voltage
generate a 300hz signal --> read voltage
.
.
generate a 1000hz signal --> read voltage
.
generate a 20000hz signal --> read voltage

Therefore, it is not necessary for the ESP32 to have a high sampling speed, since the only thing that must be stable is the signal from the AD9833, the ESP32 only has to read the voltage of the filter output and send it through the serial port. ..

I am using pin 34 of the ESP. And I would like to know if, according to your criteria, you see the code aimed at the case, or if there is something that you would change about the code.

I should not capture a 20khz signal, I should take the voltage value at the output of an audio filter that is fed with that signal... that is...

I must generate a stable signal of (say) 10Khz, give it to the input of a filter, and read the output voltage of that filter...
Therefore, the ESP sampling rate does not need to be 40KHz.

Below I show you a scheme that uses an Arduino instead of an ESP32, but the idea is the same,

Here is something of a "code review."

I am doing a project to graph the frequency response of an audio filter

You code is currently devoid of comments. While there are some theories that say your code should be obvious enough to not need comments in the code itself, you should at least have a header at the top of the file, saying what it does. And your name. And a copyright notice/license.

AD9833 gen(FNC_PIN);

I had to guess that an AD9833 was some sort of function generator, since there was no comment, and "gen" is pretty short for a descriptive name. How about:

   AD9833 funcGen(FNC_PIN);    // AD9833 Function generator on the designated pin

#define Lectura 34

Similarly, I don't know what is on pin34, so another comment would be nice.

int frequencyStep = EndFrequency / vectorLength;

This assumes that StartFrequency is 0. That seems unnecessary and potentially dangerous.


delay(10);

10ms seems a very short time to measure response at audio frequencies. It just won't work at all for frequencies below 200Hz, right (below Nyquist)? That's well within audio range.

10 should be one of the constants you #define at the top of the program. Unless you decide to make it variable depending on the current frequency (which might be a good idea.)


JsonArray jsonArray = doc.to<JsonArray>();

I'm not familiar with the JSON libraries, but they seem like they might be pretty heavy-weight for what you are doing (at least, so far.) For instance, during acquisition, you could store one integer ADC value per frequency...

I would probably implement separate functions for the acquisition of data from the send/print of the data. That would make it easier to change output routines.


This has the usual Serial issues (are lines going to be terminated with "\n", or will it be "\r\n", or something else?

An error message as an else clause would be good (showing the "invalid command.")

the signal should be a sine wave, not a square wave

what is the device measuring the output of the filter?

typically it's an ADC that is sampling the signal, expected to be a sinusoid, and capturing it peak-to-peak amplitude

How`s that?? If you want to measure 20KHz, you need at least 40KHz sample rate.
Why D1 on the input of ADC, you are measuring half wave?

How will A0 ever get lower?
Through the diode it will get higher and higher...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.