Notifications
Clear all

Platformio/C++

28 Posts
7 Users
2 Likes
3,078 Views
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@gam

I'll back off for now to give you a chance to think and digest the inflow of suggestions and information.

I'm not an expert C programmer, but my understanding is that an unsigned int can handle larger numbers because it doesn't handle negative numbers, while a signed int can have a positive or a negative value.

SteveG


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@codecage

I'm not an expert C programmer, but my understanding is that an unsigned int can handle larger numbers because it doesn't handle negative numbers, while a signed int can have a positive or a negative value.

The left most bit value in a signed number is used to indicate a + or - and thus will halve the number of possible bits combinations available to represent an unsigned number.

 

 


   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

OK!  I looked up signed / unsigned in C++.  I was unaware of the difference and the unsigned came from a section I copied in.  Arduino doesn't care I guess.  I changed all to signed and the errors disappeared.   Don't know if program works but now I can move forward with it.

Thanks much

Greg


   
ReplyQuote
noweare
(@noweare)
Member
Joined: 4 years ago
Posts: 117
 

C, C++ are strongly typed languages. Python, on the other hand, is not. Once you know that you know python does a lot of things for you in the background.


   
frogandtoad reacted
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@codecage

Posted by: @codecage

I'm not an expert C programmer, but my understanding is that an unsigned int can handle larger numbers because it doesn't handle negative numbers, while a signed int can have a positive or a negative value.

That's right Steve... an unsigned integer can handle a larger number than a signed integer - This is purely mathematics of binary numbers.

An unsigned integer can also overflow (i.e:- back to zero and continue on), whereas going beyond a signed integer's range is actually undefined behavior, and could blow up your system 😉

Cheers.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@gam

Posted by: @gam

Arduino doesn't care I guess.

It cared enough to give you a warning 😉

You can also force it to care more if you wish, by turning up the compiler warnings etc... under File -> Preferences -> Compiler...

Cheers.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@robotbuilder

Posted by: @robotbuilder

The left most bit value in a signed number is used to indicate a + or - and thus will halve the number of possible bits combinations available to represent an unsigned number.

Indeed, just to make it clear for the readers, it is often depicted using the acronym: MSB (Most Significant Bit), whereas LSB (Least Significant Bit).

If anyone is interested in binary addition and subtraction, look up 2's compliment, where you perform subtraction via addition 😉

Cheers.


   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

@noweare,   Which raises the question,  should I be trying to learn C++ or Python.  Keeping in mind that I'm a hobbyist and intend to mostly work with micro controllers.

I've read some on Python and see there are lots of local groups in meetups around KC. They all say it's so much easier than C++.  Is there a way to view a project in both Python and C++?  I think that would help me understand the differences.

Thanks

Greg


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@gam

I use both, so I would recommend you learn both.  Since you are using it as a hobbyist, you don't need to learn everything about each language as quickly as possible like you might if your livelihood depended on it.

Just learn and add to your knowledge as you go.  Using it and making the mistakes as you go reinforces what you have learned and all without a boss and deadlines nipping at your 180! 🤣 

SteveG


   
ReplyQuote
noweare
(@noweare)
Member
Joined: 4 years ago
Posts: 117
 

That's a tough question. I only really know and use C. I don't really use C++. The C language was designed for systems programming at the hardware level so it is IMO the best for pushing bits around and being very efficient at that level.

I have learned some python. There are more microcontrolers available with the resources that allows it to be programmed using python. It is a very high level language so there is a lot going on under the hood that you as a python programmer don't have to deal with. Going from C to python it feels like there is a bunch of missing steps, lol. But you can get a lot done with little coding.

IMO for embedded programming and being a hobbyist, C will allow you to program all microcontrollers. Ones that have a lot of resources (i.e. memory) and those that do not have many resources like the 8 bit microcontrollers. It is also a "small" language. There is not much syntax you have to learn so you can kind of digest it easier than other languages.

As a hobby there is so much to learn depending what direction you head in. You are going to have to learn electronics, mechanics (if you get into robotics or building machines), physics etc.. so I would only concentrate on using on language and getting good at one before moving on. 

You can even just start with the arduino syntax. That will get you far. Everything you need is right on the arduino website in the Reference section. From there you can start to learn C and the C library.

Good luck

 

 

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@gam

Just learn Arduino C++ first it will give you the basic idea of C++ programming using classes.  Even if you don't write your own classes you still use them with a C++ compiler.

With the Arduino you will have classes like the Serial class and Servo class and so on.

A Raspberry Pi would best be programmed using Python with all its library and tutorial support.

My 2 cents worth 🙂

 


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@robotbuilder

I guess if I had saved up all of "my 2 cents worth" for my entire life I'd be a millionaire right now without having won the lottery!  🤣 🤣 🤣 🤣 🤣 🤣 🤣 🤣 

And I have now finally realized that if I wanted any hope of winning the lottery I need to buy a ticket!

SteveG


   
ReplyQuote
 GAM
(@gam)
Member
Joined: 3 years ago
Posts: 58
Topic starter  

Thanks for everyone's replies.  I have a fair understanding of electronics with assoc degree from 1970 and years of field service on medical hematology equipment. With the sensors and boards available today I'm good with the wiring and hardware.  Weak on programing them to do what I want.  I will take the advice and keep going forward with C++ as it seems closely related to the Arduino project I have done.   Hope to learn some Python along the way.  True you learn from mistakes!  I should be learning a lot. 

 

Greg   

 


   
ReplyQuote
Page 2 / 2