ESP32 Arithmetic Error - Page 1
Forum section: electronics / general

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: February 07, 2023, 11:03:23 pm
content: Can anybody tell me just what is wrong with this code posted as working but won't compile without this error?"suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses]"I tried several parentheses in the normal way I would use them but nope.The line in question:cmd_si5351(60,(R<<4)&0x70|(P1>>16)&0x03);Here's a photo.

author: langwadt
author_rank: Super Contributor
timestamp: February 07, 2023, 11:12:10 pm
content: cmd_si5351(60,((R<<4)&0x70)|((P1>>16)&0x03));?

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: February 07, 2023, 11:22:13 pm
content: Thanks, it seems to get past that bit but now it's on to something else:sprintf(str, "%3d, %03d, %02d", frq/1000000, (frq/1000)%1000, (frq/10)%100 );format '%d' expects argument of type 'int', but argument 3 has type 'long int' [-Werror=format=]And this was shown to be working with the download link.Any advice?I've been in hospital for the last 2 months and the thinker box is lagging behind by 4.

author: SiliconWizard
author_rank: Super Contributor
timestamp: February 08, 2023, 12:06:44 am
content: The original statement was already too readable "cmd_si5351(60,(R<<4)&0x70|(P1>>16)&0x03);", which is probably why your latest post uses a minuscule font.

author: ejeffrey
author_rank: Super Contributor
timestamp: February 08, 2023, 01:01:28 am
content: frq must be declared 'long int' outside of the posed code snippet. The sprintf format specifier %d expects an integer. In C, these are not the same type even if they are the same size. The solution is to change the format specifier to %ld.I'm guessing that frq is actually declared with something like int32_t, or another fixed width type which is typedef'ed by stdint.h into 'long int' but would be different on another platform. If you want to be cross platform you can fix this a couple of ways.1) You can use the "PRId32" or similar marcros which are defined to have the correct type for fixed width types. This works fine, but dramatically decreases readability, and doesn't provide a solution for other typedefs (such as user or platform defined ones).2) You can use the format specifier %jd and cast the value to intmax_t. This is more readable, and works for any signed integral type, but likely carries runtime overhead.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: February 08, 2023, 01:19:28 pm
content: It was declared early on as a Global, so I don't understand why except for!!long frq=init_freq;I can provide the code from the author and the associated page if anyone can make it work.I'm still learning to walk all over again and a nice project would distract me from my troubles, 2 months and more to come, but I can't figure it out, Perhaps someone here would be so kind.I was going to make 2 units, with a friend of mine (my age)receiving one unit for free. Hehelped me with a lot of things while I was in hospital.So, the project is a signal generator/VFO that would I'm sure he would like if he knew he was getting it.The code is a strange mish-mash of a Japanese ham's work and has a lot of undeclared and unused variables.Anybody like to help the aged and infirmed while in recovery, set this code straight where it will compile?

author: paulca
author_rank: Super Contributor
timestamp: February 09, 2023, 10:53:10 am
content: My advice would be to delete the obfuscated Martian and write it in human readable code instead.cmd_si5351(60,(R<<4)&0x70|(P1>>16)&0x03);Split it up.int aNamedThing = 60;#define A_CONSTANT 4#define ANOTHER_CONSTANT 0x70#define YET_ANOTHER_CONSTANT 0x03#define AND_ANOTHER_CONSTANT 16long anotherThing = (R<<A_CONSTANT)&ANOTHER_CONSTANT;long aThing = (P1>>AND_ANOTHER_CONSTANT)&YET_ANOTHER_CONSTANT;Thencmd_si5351(aNamedThing , anotherThing | a Thing );Now you can actually read it, assuming Thing and Another thing have actual readible names.The compiler will optimise it and remove most of it, so worry not.Complex expressions like that are obsfucation and it is a sign of a non-profressional programmer, most likely a Solo hacker who doesn't care if anyone, including himself can read and understand it in 6 weeks.

author: ledtester
author_rank: Super Contributor
timestamp: February 09, 2023, 03:58:56 pm
content: Quote from: paulca on February 09, 2023, 10:53:10 amI think adding a comment likeCode:// form the byte with bits: 0 | R_2 | R_1 | R_0 | 0 | 0 | P1_17 | P1_16// i.e. R[2:0] in the top nybble and P1[17:16] in the lower nybble...would be more useful.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: February 09, 2023, 04:15:17 pm
content: I'm afraid you're going faster than my brain can handle right now. The stay in hospital took a lot out of me mostly physical and mental.I get what you are trying to tell me but the application of it feels impossible right now.Please let me show you all the original article and code and please just attempt to compile it for a standard ESP32 and let me know if I am that addled or is it the code.Here are the necessary links for this riddle. This has nothing to do with me or anyone else's post.I just found it interesting as a signal generator and that display!!https://www.hackster.io/mircemk/universal-vfo-10-khz-160-mhz-with-retro-analog-scale-c7c5b6Thanks for everyone's help so far here.

author: paulca
author_rank: Super Contributor
timestamp: February 09, 2023, 06:13:10 pm
content: Quote from: ledtester on February 09, 2023, 03:58:56 pmAye. Then you later need to go look up what those bits are. Why not do everyone a favour and just name them with constants?Someone else reading your code is going to ask, "What does that do?"Making your code completely unreadable and full of magic numbers just makes it harder for them. Most people who have been on the receiving end of this in their career go out of their way not to do it to others.Yes, YOU know what they are NOW, but you in 6 months might not. Someone else might not. So they literally have to go get the reference manual out to understand what the code does. Just to save a few hundred characters of text.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: February 26, 2023, 03:33:15 am
content: Forget the math errors. The author did not mention only the ESP-32-S2 variant will work due to size constraints.I compiled all of the Arduino sketches that did not work from the original Japanese all the wat through the latest versions found on the Intertoobs. All of them finished compiling.Whether they work or not we'll see within the week. I don't have an S2 on hand right now.I'm looking for a 4M Flash & 2M PSRAM version.The big problem is that Amazon, Digi-Key, Mouser etc do not explain which S2's PSRAM equals what by a specific part number.I even see several listings that say ESP-32-S2 but then describe an 8286 down below for the item and photo aboveNow I have the old issue of the seller having no clue what thy are selling.Stand by..............................................................................

author: tooki
author_rank: Super Contributor
timestamp: February 26, 2023, 01:10:44 pm
content: Quote from: Quarlo Klobrigney on February 07, 2023, 11:03:23 pmAssuming that you are simply attempting to compile this:Quote from: Quarlo Klobrigney on February 09, 2023, 04:15:17 pm...then there'snothingwrong with the code. It compiles without issue for me using the Arduino IDE 1.8.16 with default settings, set up for an ESP32 dev module. If you change the settings to give "more" or "all" compiler warnings, then you see these warnings.It could be as simple as you needing to reset your build environment.Preferences:- Compiler warnings: default.- Additional boards manager URLs:https://dl.espressif.com/dl/package_esp32_index.jsonESP32 board support v.1.0.6Tools:- Board: ESP32 Dev ModuleThe rest should be the defaults.Quote from: Quarlo Klobrigney on February 26, 2023, 03:33:15 amWhere did you get that idea?!?It only uses a fraction of the standard ESP32's resources:QuoteAlso, FYI, PSRAM isn't even used automatically, so if you run out of regular RAM, you can't just get a module with extra PSRAM and then upload your code. You have to modify the code to push things into PSRAM.I can't test the code since I don't have the correct display nor the si5351, but the code does compile.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: February 27, 2023, 09:17:07 am
content: Well you are making a lot of assumptions.Who told me that it needed an S2, one of the latter authors who confirmed that the original project with an ESP32, ran out of memory.The code still doesn't compile for a non S2 for all the versions of the original code.I don't care if the code fits or not, it doesn't compile. Iv'e still yet to program anything because I do not have an S2.Of course the json file was installed long ago.The compiler warnings had never been turned off until I kept getting errors weeks ago.Why would any good programmer ever turn off errors anyway it is counter intuitive to doing the job right.Yes, the settings are exactly the same as yours which are still the same as when I started.Any way I want more memory and PSRAM just because, not because it will fix this. I want the max because I don't like to buy things twice. More PSRAM equates to spiffs not running short of space.Expressif's site is all over the map and still doesn't give a correct part number for 2M or 4M (if available) to order from a vendor-distributor.Quote from: tooki onYesterdayat 08:10:44

author: m98
author_rank: Frequent Contributor
timestamp: February 27, 2023, 07:46:02 pm
content: The ESP32 should have more than enough resources for this application. Maybe just ditch that code and implement it yourself with ESP-IDF and LVGL.

author: tooki
author_rank: Super Contributor
timestamp: February 27, 2023, 10:49:14 pm
content: Quote from: Quarlo Klobrigney on February 27, 2023, 09:17:07 amI am notassuminganything!!! I did not speculate that it would work. I tested it. I downloaded the code YOU linked, and then SUCCESSFULLY COMPILED IT FOR ESP32 (NOT S2) on the first try.I just can’t test whether it’s actually working because I don’t have the peripherals in question.Is the project you linked to NOT the “original code”? That project didn’t use an S2, either.Also: Any assumptions the reader has to make is because YOU didn’t provide the actual information. That’s your fault, not mine.Quote from: Quarlo Klobrigney on February 27, 2023, 09:17:07 amI said nothing about what is and isn’t good practice. I only said that those warnings (not errors!) do not occur with the default warnings level.If you don’t like what the default warnings are, please argue with the Arduino authors about it, not me. I didn’t decide them.Quote from: Quarlo Klobrigney on February 27, 2023, 09:17:07 amWell clearly not, since you have the warnings set to a different level.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: February 28, 2023, 04:37:41 am
content: As I have already said, "I've been in hospital for the last 2+ months and the thinker box is lagging behind by 4 months (or years)".I'm not capable of that level of thinking at this time.I was hoping for advice-help for code correction, not criticism of my abilities at this time.I do wish more have read the entire thread.Edited because garbage is posted along with post such as errant tags and font issues.Only this browser on this site does it.Quote from: m98 onTodayat 14:46:02>The ESP32 should have more than enough resources for this application. Maybe just ditch that code and implement it yourself with ESP-IDF and LVGL.

author: tooki
author_rank: Super Contributor
timestamp: February 28, 2023, 06:35:49 am
content: Quote from: Quarlo Klobrigney on February 28, 2023, 04:37:41 amI am sorry you’re not feeling well, and I hope you feel better soon.Quote from: Quarlo Klobrigney on February 28, 2023, 04:37:41 amBut the code doesn’t need correction. I tested the code and it compiled without error on the first try. So something is wrong with your build environment.Do you have another computer to try on?Also, a thought: try temporarily uninstalling the libraries in your Arduino IDE, just to make sure there isn’t some library versioning conflict.