Here is the section:
21212. (a) A person under 18 years of age shall not operate a
bicycle, a nonmotorized scooter, or a skateboard, nor shall they wear
in-line or roller skates, nor ride upon a bicycle, a nonmotorized
scooter, or a skateboard as a passenger, upon a street, bikeway, as
defined in Section 890.4 of the Streets and Highways Code, or any
other public bicycle path or trail unless that person is wearing a
properly fitted and fastened bicycle helmet that meets the standards
of either the American Society for Testing and Materials (ASTM) or
the United States Consumer Product Safety Commission (CPSC), or
standards subsequently established by those entities. This
requirement also applies to a person who rides upon a bicycle while
in a restraining seat that is attached to the bicycle or in a trailer
towed by the bicycle.
And, a "street" ....
590. "Street" is a way or place of whatever nature, publicly
maintained and open to the use of the public for purposes of
vehicular travel. Street includes highway.
And, thus, a "highway" ...
360. "Highway" is a way or place of whatever nature, publicly
maintained and open to the use of the public for purposes of
vehicular travel. Highway includes street.
And, finally, a "sidewalk" ...
555. "Sidewalk" is that portion of a highway, other than the
roadway, set apart by curbs, barriers, markings or other delineation
for pedestrian travel.
Note that a "sidewalk" is part of the "highway" (aka "street").
The officer could have also cited you for the earphones and riding on the sidewalk. You got lucky.
Next time, don't dangle the helmet on the handlebars, WEAR IT. The law does not say you have to wear it only when you want to, it says you SHALL wear it.
And, fear not, if your parents do not have the money, the court may allow you to work it off in community service. Most judges do not wish to saddle parents with the child's burden, anyway.