# I need a little help with a sketch using Arduino IDE

**URL:** <https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362>\
**Category:** Uncategorized\
**Created:** [10 February 2023 20:46 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362 "2023-02-10T20:46:43Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![MarvinYYC](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/marvinyyc/32/7741_2.png) [@MarvinYYC](https://forum.core-electronics.com.au/u/MarvinYYC)\
**Post date:** [11 February 2023 22:44 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/21 "2023-02-11T22:44:14Z")

</div>

Unfortunately I don’t understand that _WaitFunc_ code or the _FlashRedLED_ code or how it is supposed to work. I will have to look for an example of a simpler code for this function. One I understand.

I tried putting in additional debug messages in the _OnDataRecv_, but it was not able to compile them.

---

<div class="post-metadata">

**Author:** ![Jacob213709](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jacob213709](https://forum.core-electronics.com.au/u/Jacob213709)\
**Post date:** [12 February 2023 00:46 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/22 "2023-02-12T00:46:07Z")

</div>

G’day Marvin,

I have just spent a few days learning how to combine sketches and also had a slow start. I haven’t read this entire thread, but the method that worked for me was:

Take the separate sketches  
Sketch A  
Sketch B

Then add sketch B one bit at a time into sketch A. For example:

Sketch A libraries  
\*Sketch B libraries  
Sketch A setup  
Sketch A loop

Then compile, upload, give code and error messages (if any) to ChatGPT for solution, implement solution.

Then the next bit of Sketch B:

Sketch A libraries  
\*Sketch B libraries  
Sketch A setup  
\*Sketch B setup (copied and pasted after the A parts, but still inside the one setup bracket. I.e. don’t have 2 setup sections)  
Sketch A loop

Compile, upload, etc.

Tell me if my explanation doesn’t make sense, because it did work for me when combining an NTRIP Client and Digital Compass.

---

<div class="post-metadata">

**Author:** ![Robert93820](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@Robert93820](https://forum.core-electronics.com.au/u/Robert93820)\
**Post date:** [12 February 2023 01:04 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/23 "2023-02-12T01:04:31Z")

</div>

Hi All

> [@Jacob213709](#):
>
> copied and pasted

Be a little bit careful here. Sometimes somehow (in the control of the Gods) this does not work as expected and you could get some funny (I mean you can’t find the cause) errors when compiling. The cure seems to be very carefully type in the code. Seems you can somehow pick up or introduce some hidden (non printable???) beasties during the process. I have had to do this with a complete sketch at one time. When copied and pasted it just would not compile.  
Cheers Bob

---

<div class="post-metadata">

**Author:** ![MarvinYYC](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/marvinyyc/32/7741_2.png) [@MarvinYYC](https://forum.core-electronics.com.au/u/MarvinYYC)\
**Post date:** [12 February 2023 14:53 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/24 "2023-02-12T14:53:00Z")

</div>

Thanks Jacob  
The sketch compiles without error it just doesn’t run the way I expect it to. But I am a novice, so that doesn’t mean much. . . When I add the second part of the code to the original sketch the first sketch seems to get stuck after it runs the second sketch. . . . I’ve been trying to figure it out for several days with no luck.  
I might give chatgpt a go, although I’m not sure how to explain to a computer what is not working with my code 🤪

---

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [12 February 2023 20:47 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/25 "2023-02-12T20:47:16Z")

</div>

> [@MarvinYYC](#):
>
> I’ve been trying to figure it out for several days with no luck.

You won’t figure it out without much more information. You haven’t added enough debug statements, and your debug statements aren’t giving you the full picture. You need at least one for every start and end of a method, and one for every time through any loop. And mostly they should show at least one variable that is relevant to what is happening (eg, argument to a method, result of a method, counter or other exit condition for a loop). When you have enough information the picture will become clearer. Then you can get assistance with resolving it.

---

<div class="post-metadata">

**Author:** ![Jacob213709](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jacob213709](https://forum.core-electronics.com.au/u/Jacob213709)\
**Post date:** [12 February 2023 21:17 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/26 "2023-02-12T21:17:41Z")

</div>

Now that you mention it, I did find it very very useful to put serial.print(“ [Whatever just happened] ”) after basically everything. Definitely a good idea. Also helps ChatGPT figure it out if you can tell it what line it stopped at.

Also, on the point about not being able to explain. You can just type “the following code is not working. It just hangs. I think the problem is in the loop section. [Paste whole sketch]”.

---

<div class="post-metadata">

**Author:** ![MarvinYYC](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/marvinyyc/32/7741_2.png) [@MarvinYYC](https://forum.core-electronics.com.au/u/MarvinYYC)\
**Post date:** [12 February 2023 22:31 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/27 "2023-02-12T22:31:03Z")

</div>

Thanks Jeff  
I have more debug statements than I know what to do with 🤪

The code I have on Github doesn’t include the numerous debug statements that I recently added.

Still not having any luck. 😕

---

<div class="post-metadata">

**Author:** ![MarvinYYC](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/marvinyyc/32/7741_2.png) [@MarvinYYC](https://forum.core-electronics.com.au/u/MarvinYYC)\
**Post date:** [12 February 2023 22:34 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/28 "2023-02-12T22:34:00Z")

</div>

Thanks for the suggestion to try ChatGTP\>

This is what ChatGTP returned:

> It’s difficult to say for certain without more information, but one thing that stands out is that the http.POST() method is being called with the url\_1 variable, which contains the URL used to initiate the HTTP connection with http.begin(). This may cause unexpected behavior, as http.POST() should be called with the message to be sent as the argument.
> 
> Additionally, you may want to include more error handling in your code to help identify any issues. For example, you could add Serial.println(http.errorToString(httpCode).c\_str()); to print the error message if the HTTP request fails, which could give you more information about the problem.

It has me looking down a whole other rabbit hole 🤔  
Reviewing the way that the CallMeBot API works and the syntax. Just one of the problems with a nubie using code that someone else wrote.

---

<div class="post-metadata">

**Author:** ![Trent5487676](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/trent5487676/32/4583_2.png) [@Trent5487676](https://forum.core-electronics.com.au/u/Trent5487676)\
**Post date:** [13 February 2023 04:55 UTC](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362/29 "2023-02-13T04:55:20Z")

</div>

Hi Marvin,

Debugging code is an entirely separate skillset and arguably more useful than writing it from scratch. @Jeff105671 and @Jacob213709 have shared some top points though so I’m sure it’s only a matter of time until you locate the issue using their tips.

@Robert93820 's point about copying and pasting code is also something that newbies get stung by all the time. Good text editors won’t do it, but sometimes copying code of a webpage will mangle what gets copied with hidden characters and all sorts of other nonsense. Tabs being converted to space characters is also very common.

As always step 0 is to add more debug lines than you think you could possibly need in as many places as possible.

If you have access to a hardware debugger and can step your code through its operation step by step that can also be a game-changer, but it won’t work in every situation.

If in doubt, go back to the simplest form of code that worked properly, and add the smallest chunks of new code possible, testing as you go.

[Previous page](https://forum.core-electronics.com.au/t/i-need-a-little-help-with-a-sketch-using-arduino-ide/16362.md?page=1)
